Solved

Popup code on Javascript onLoad event won't work

Posted on 2007-04-11
9
1,272 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 
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

Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

Question has a verified solution.

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

Suggested Solutions

This article discusses how to implement server side field validation and display customized error messages to the client.
Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

739 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