HTML & WEB-Design

Moderators: Jonathan
Number of threads: 1253
Number of posts: 3360

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
detecting back link page display event Posted by Josh Code on 28 Apr 2008 at 10:02 AM
In all the browsers I've looked, the onload event is not invoked when a page is displayed using a back link.

What is the best way to detect that displaying event?

If you want to try some of your ideas out, I have some code below for you to copy and paste to get you started.
<html>
<head>
 <script language="JavaScript" type="text/javascript">
/* <![CDATA[ */


function loading()
{
  alert("loading..");
}

/* ]]> */
 </script>
</head>
<body onload="loading()">

Saw the alert?

Click <a href="next.html">Next page</a> and the back link to see that the onload doesn't happen again.

</body>
</html>
Report
Re: detecting back link page display event Posted by CyGuy on 4 May 2008 at 5:42 PM
Hi Josh Code,

This problem is certainly frustrating, especially when my web host is configured to non-parsed headers due to the virtual shared environment... BUT here is your workaround:

<html>
<head>
 <script language="JavaScript" type="text/javascript">

/* <![CDATA[ */
var loaded = false;

function loading()
{ 
 if (!loaded){
  loaded=true;
  alert("loading..");
 }
}

function leaving()
{
  loaded=false;
}
/* ]]> */
 </script>
</head>
<body onload="loading()" onunload="leaving()">

Saw the alert?

Click <a href="next.html">Next page</a> and the back link to see that the onload doesn't happen again.

</body>
</html>

Original worked fine on IE7, so I ran it through NS



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.