Solved

Popup code on Javascript onLoad event won't work

Posted on 2007-04-11
9
1,267 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
This video teaches users how to migrate an existing Wordpress website to a new domain.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

776 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