Solved

Popup code on Javascript onLoad event won't work

Posted on 2007-04-11
9
1,256 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 29

Expert Comment

by:rdivilbiss
Comment Utility
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
Comment Utility
I assume there are no popup blockers in the middle that might be blocking the popup, correct?
0
 
LVL 29

Expert Comment

by:Badotz
Comment Utility
<body onload="popup()">

is wrong. It should be:

<body onload=popup;>
0
 
LVL 29

Expert Comment

by:Badotz
Comment Utility
oh, wait - I'm wrong - thinking it was

window.onload = popup;

which you might try instead of

<body onload="popup()">
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

744 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

16 Experts available now in Live!

Get 1:1 Help Now