?
Solved

OnClick works, but not OnLoad?

Posted on 2006-05-27
6
Medium Priority
?
906 Views
Last Modified: 2007-12-19
I'm trying to run the following script onLoad instead of onClick, but it does nothing onLoad.  The script generates a css popup window onClick by changing the visibility of the div.  

How can I get it to run onload?

(I've linked to the script if it helps - 3rd party)


<html>
<head>
<script src="http://www.litotes.demon.co.uk/js_info/scripts/WindowMngr.js" type="text/javascript"></script>
</head>
<body>

<a href="#" onclick="return WindowMngr('win16610479');">Click Here</a>


<!--Popup Window Code-->
<div id="win16610479">
  <h3><a>Title</a></h3>
  <div><div><div><p>Text</p></div></div></div>
</div>
<!--End Popup Window Code-->

<script>WindowMngr('win16610479', WindowMngr.CLOSEABLE|WindowMngr.DRAGABLE|WindowMngr.RESIZEABLE|WindowMngr.VERTICAL_SCROLL);</script>
                                     
</body>
</html>
0
Comment
Question by:cotton9
  • 4
  • 2
6 Comments
 
LVL 10

Expert Comment

by:ClickCentric
ID: 16777301
You've tried changing:

<body>

to

<body onload="WindowMngr('win16610479', WindowMngr.CLOSEABLE|WindowMngr.DRAGABLE|WindowMngr.RESIZEABLE|WindowMngr.VERTICAL_SCROLL);">

And it didn't work?
0
 
LVL 10

Expert Comment

by:ClickCentric
ID: 16777316
Oh wait, on a closer look, you weren't running onload, you were running it inline.  

And I think I see where the problem is.  Change what I have above to:

<body onload="WindowMngr('win16610479', WindowMngr.CLOSEABLE|WindowMngr.DRAGABLE|WindowMngr.RESIZEABLE|WindowMngr.VERTICAL_SCROLL);WindowMngr('win16610479');">
0
 

Author Comment

by:cotton9
ID: 16777328
Thanks for the help, but that isn't working either.  Nothing happened.

The code above is actually fully functional (with onclick) if you want to see the desired effect or test it out.  

0
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!

 
LVL 10

Accepted Solution

by:
ClickCentric earned 1020 total points
ID: 16777332
Actually, you're getting a race condition.  Use this instead:

<html>
<head>
<script src="http://www.litotes.demon.co.uk/js_info/scripts/WindowMngr.js" type="text/javascript"></script>
</head>
<body>

<a href="#" onclick="return WindowMngr('win16610479');">Click Here</a>


<!--Popup Window Code-->
<div id="win16610479">
  <h3><a>Title</a></h3>
  <div><div><div><p>Text</p></div></div></div>
</div>
<!--End Popup Window Code-->

<script type="text/javascript">
WindowMngr('win16610479', WindowMngr.CLOSEABLE|WindowMngr.DRAGABLE|WindowMngr.RESIZEABLE|WindowMngr.VERTICAL_SCROLL);
setTimeout("WindowMngr('win16610479')",100);
</script>
                               
</body>
</html>

The short timeout should be enough to give the first call time to set up the parameters.  Worked when I tested it.
0
 

Author Comment

by:cotton9
ID: 16777341
Darn those race conditions!  

Thanks for the help ClickCentric
0
 
LVL 10

Expert Comment

by:ClickCentric
ID: 16777367
Not a problem.   Something seemed fishy which caused me to try it out for myself and I knew the coding was right and no errors were getting thrown, so on a hunch I tried the timeout and that did it.  You may want to play with the value a bit.  It actually works for me with the timeout set to 1 instead of 100, but I have a pretty fast computer.  You have to plan for the people who still have the pentium 90's out there. :P
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…
Suggested Courses

840 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