Solved

Popup code on Javascript onLoad event won't work

Posted on 2007-04-11
9
1,262 Views
Last Modified: 2013-11-19
I have the following, very simple code running on a page:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Gift Cards</title>
<script language="javascript" type="text/javascript">
      function popup() {
            window.open('gtpage.html', 'tourpopup', 'width=660,height=400,location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no,directories=no');
      }
</script>
</head>

<body onload="popup()">
</body>
</html>

All it really does is load a popup window with a Flash guided tour, but this code doesn't do anything. Adding a button on the page, with an onload event that calls the popup() function works just fine, but I can't get it to pop up the window once the blank page loads.

Can anybody tell me what the problem is? I even tried adding "return true;" to the end of the function, but it doesn't help.

Thanks.
0
Comment
Question by:TerranRich
9 Comments
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 18891475
Try rewriting it as ...

      function popup() {
            var w = window.open('gtpage.html', 'tourpopup', 'width=660,height=400,location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no,directories=no');
            w.focus();
      }

And then use onload="popup(); return false;"

How does that work?  As you are testing this are you fully reloading the page or just using Back or Refresh?

Let me know if you have a question or need more info.

bol
0
 

Author Comment

by:TerranRich
ID: 18891536
I'm refreshing it the right way, clearing the cache.

And your suggestion unfortunately didn't work.
0
 
LVL 29

Accepted Solution

by:
rdivilbiss earned 50 total points
ID: 18891809
While I see no obvious reason why the above will not work, I suggest you always check for an open child before creating one.

The obvious thing that comes to mind is, of course, pop up blockers in browsers.

The next thing could be timing...e.g. the onload is trying to execute before the page has fully loaded.



<script type="text/javascript">
<!--
var childPopup = null;

function popup() {
      if (childPopup != null) {
            if (childPopup.closed == false)
                  childPopup.close()
      }
    childPopup = window.open('gtpage.html', 'tourpopup', 'width=660,height=400,location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no,directories=no');
    return childPopup;
}

//-->
</script>

<body onload="setTimeout(popup,1000);">

The setTimeout will wait a second before attempting to open the child window.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 29

Expert Comment

by:rdivilbiss
ID: 18891828
If pop up blockers are an issue, you could put your tour page HTML inside a division and pop over the division after loading the page.

This example uses a form, but the content of the division is not relevant.


http://www.rodsdot.com/ee/popOverForm.asp
0
 
LVL 3

Expert Comment

by:dmagliola
ID: 18891897
I assume there are no popup blockers in the middle that might be blocking the popup, correct?
0
 
LVL 29

Expert Comment

by:Badotz
ID: 18908928
<body onload="popup()">

is wrong. It should be:

<body onload=popup;>
0
 
LVL 29

Expert Comment

by:Badotz
ID: 18908936
oh, wait - I'm wrong - thinking it was

window.onload = popup;

which you might try instead of

<body onload="popup()">
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Trouble inserting a variable  in javascript 7 42
Replace &lt; with < 14 54
form button worked now it doesnt anymore 9 36
How to write an English digest paper 6 17
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now