• 0
Sign in to follow this  
Followers 0

Simple javascript pop-up

Question

Posted

Any idea how to make an javascript popup? I already added the code from below but whenever I click the links it opens the same page ([b]demo.html[/b]):


[quote]
<script type="text/javascript">
function popup(){
cuteLittleWindow = window.open("demo.html", "littleWindow", "location=no,width=614,height=222");
}</script>



<center>
<font face="Verdana"><font size="-1"><b><a href="http://www.mywebsite.com/"><font color="#000000">Home Page</font></a> | <a href="javascript:popup()">Demo</a> | <a href="javascript:popup()">Contact</a></b></font></font>
</center>
[/quote]

..and it looks like this:

[img]http://i.imgur.com/DG6VE.png[/img]

What I'm doing wrong? Cause I know it's pretty simple but I'm not good a html. Thanks.

Share this post


Link to post
Share on other sites

8 answers to this question

  • 0

Posted

Have you used your browser's debugger to see if any script errors are being flagged?

Share this post


Link to post
Share on other sites
  • 0

Posted

Well, it works for me in Chrome, Firefox and IE 10. Normally I would say when you use the "javascript:xxx()" form in an href, to terminate it with a semi-colon ("javascript:xxxxx();")... but rules aren't very strict anymore and that seems to work in recent browsers. Is the window opening behind your browser? Do you have popups disabled or some other security setting enabled?

Share this post


Link to post
Share on other sites
  • 0

Posted

Yes, there are no errors and there's not any other Javascript code apart from that. It's a pretty simple page, nothing complex.

The window opens as it should in the front. Maybe I didn't explained well the problem. The script is working but what doesn't work is this:

1. I have 3 menus: HOME | DEMO | CONTACT (so 3 pages) INDEX.html - DEMO.html and CONTACT.html
2. The javascript resides on the INDEX.html
3. If I click on DEMO it opens the DEMO.html as it should in the front of my browser.
4. But if I click on CONTACT it [b]opens the same DEMO.html and not[/b] CONTACT.html

Share this post


Link to post
Share on other sites
  • 0

Posted

I'm not really sure what you're asking, but if you want your links to open a new window, the "name" parameter needs to be: name="_blank". The value "littleWindow" will always point to the same window with every click. "_blank" will spawn a new window/tab with every click.

Share this post


Link to post
Share on other sites
  • 0

Posted

The mistake is in the popup function since demo.html is hard coded instead of a variable...

Share this post


Link to post
Share on other sites
  • 0

Posted

[quote name='Copernic' timestamp='1353274794' post='595331202']
Yes, there are no errors and there's not any other Javascript code apart from that. It's a pretty simple page, nothing complex.

The window opens as it should in the front. Maybe I didn't explained well the problem. The script is working but what doesn't work is this:

1. I have 3 menus: HOME | DEMO | CONTACT (so 3 pages) INDEX.html - DEMO.html and CONTACT.html
2. The javascript resides on the INDEX.html
3. If I click on DEMO it opens the DEMO.html as it should in the front of my browser.
4. But if I click on CONTACT it [b]opens the same DEMO.html and not[/b] CONTACT.html
[/quote]

Ohhhhhhh! :) Yes, I very much misunderstood your question/problem. Use target="_blank", pass the page name as a parameter or use a separate javascript function, and also NAME the window dynamically in the open function.

Share this post


Link to post
Share on other sites
  • 0

Posted

Thank you very much, I finally got it working!

Share this post


Link to post
Share on other sites
  • 0

Posted

This was my little version to test yours...

[quote]

<script type="text/javascript">
var aPage = new Array();
var aHandle = new Array();
aPage[0] = "somepage.html";
aPage[1] = "someotherpage.html";
aHandle[0] = null;
aHandle[1] = null;

function popupbyidx(idx) {
var prefix = "winname_";
aHandle[idx] = window.open(aPage[idx], prefix + idx, "location=no,width=614,height=222");
}
function closebyidx(idx) {
aHandle[idx].close();
}
function popup(page){
cuteLittleWindow = window.open("demo.html", "littleWindow", "location=no,width=614,height=222");
}</script>

<center>
<font face="Verdana"><font size="-1"><b><a href="http://www.mywebsite.com/"><font color="#000000">Home Page</font></a> | <a href="javascript:popupbyidx(0);">Demo</a> | <a href="javascript:popupbyidx(1);">Contact</a></b></font></font>
</center>

<center>
<font face="Verdana"><font size="-1"><b><a href="http://www.mywebsite.com/"><font color="#000000">Home Page</font></a> | <a href="javascript:closebyidx(0)">Close Demo</a> | <a href="javascript:closebyidx(0)">Close Contact</a></b></font></font>
</center>
[/quote]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.