Solved

Popup code on Javascript onLoad event won't work

Posted on 2007-04-11
9
1,273 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

626 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