Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #30419 > unrolled thread

window.onload not working when using Safari's back button

Started byTuxedo <tuxedo@mailinator.com>
First post2016-05-10 22:53 +0200
Last post2016-05-11 21:39 +0200
Articles 3 — 2 participants

Back to article view | Back to comp.lang.javascript


Contents

  window.onload not working when using Safari's back button Tuxedo <tuxedo@mailinator.com> - 2016-05-10 22:53 +0200
    Re: window.onload not working when using Safari's back button JJ <jj4public@vfemail.net> - 2016-05-11 14:01 +0700
      Re: window.onload not working when using Safari's back button Tuxedo <tuxedo@mailinator.com> - 2016-05-11 21:39 +0200

#30419 — window.onload not working when using Safari's back button

FromTuxedo <tuxedo@mailinator.com>
Date2016-05-10 22:53 +0200
Subjectwindow.onload not working when using Safari's back button
Message-ID<ngthoj$v4f$1@news.albasani.net>
Hello,

If I have a window.onload event called from in a script or in the body tag, 
for example:

window.onload=alert('hello');
or
<body onload="alert('hello')">

... and after having navigated away from the page via for example a link 
and if thereafter using the browser's back button, the onload event will 
occur again when returning to the original page in FF and in other 
browsers, but not in Safari for some reason - why not?

I tested on an Ipad. Presumably Safari on a desktop OSX behaves the same as 
on the Ipad. But Chrome, which is also utilising WebKit, behaves like FF in 
this respect, so the difference appears to be Safari specific.

Is it possible to detect if a page is returned to via the back button in 
Safari?

Many thanks for any advise.

Tuxedo

[toc] | [next] | [standalone]


#30423

FromJJ <jj4public@vfemail.net>
Date2016-05-11 14:01 +0700
Message-ID<6p5if990m1pv.wcru3edh2ls.dlg@40tude.net>
In reply to#30419
On Tue, 10 May 2016 22:53:39 +0200, Tuxedo wrote:
> Hello,
> 
> If I have a window.onload event called from in a script or in the body tag, 
> for example:
> 
> window.onload=alert('hello');
> or
> <body onload="alert('hello')">
> 
> .... and after having navigated away from the page via for example a link 
> and if thereafter using the browser's back button, the onload event will 
> occur again when returning to the original page in FF and in other 
> browsers, but not in Safari for some reason - why not?

The page is probably restored (not reloaded) from the browser's memory
cache. A cache which include not just the web page resources, but also the
DOM state. An optimized browser would restore a page from cache if possible,
rather than simply reload it.

> I tested on an Ipad. Presumably Safari on a desktop OSX behaves the same as 
> on the Ipad. But Chrome, which is also utilising WebKit, behaves like FF in 
> this respect, so the difference appears to be Safari specific.
> 
> Is it possible to detect if a page is returned to via the back button in 
> Safari?

No. There's no event for browser's navigational actions except browser's own
non standard events which are only accessible from with a browser extension.

[toc] | [prev] | [next] | [standalone]


#30425

FromTuxedo <tuxedo@mailinator.com>
Date2016-05-11 21:39 +0200
Message-ID<nh01q5$ku8$1@news.albasani.net>
In reply to#30423
JJ wrote:

> On Tue, 10 May 2016 22:53:39 +0200, Tuxedo wrote:
> > Hello,
> > 
> > If I have a window.onload event called from in a script or in the body
> > tag, for example:
> > 
> > window.onload=alert('hello');
> > or
> > <body onload="alert('hello')">
> > 
> > .... and after having navigated away from the page via for example a
> > link and if thereafter using the browser's back button, the onload event
> > will occur again when returning to the original page in FF and in other
> > browsers, but not in Safari for some reason - why not?
> 
> The page is probably restored (not reloaded) from the browser's memory
> cache. A cache which include not just the web page resources, but also the
> DOM state. An optimized browser would restore a page from cache if
> possible, rather than simply reload it.

Thanks for clarifying this. It is indeed what happens with Safari and maybe 
other browsers but not in FF and the Chrome browser.

> > I tested on an Ipad. Presumably Safari on a desktop OSX behaves the same
> > as on the Ipad. But Chrome, which is also utilising WebKit, behaves like
> > FF in this respect, so the difference appears to be Safari specific.
> > 
> > Is it possible to detect if a page is returned to via the back button in
> > Safari?
> 
> No. There's no event for browser's navigational actions except browser's
> own non standard events which are only accessible from with a browser
> extension.

The issue was that the user can modify elements on the page temporarily 
which should not stay in their modified states after having left and 
returned to the same page. To work around the different browsers I can 
instead detect certain display states by inspecting various style elements 
using for example setInterval and thereafter restore the wanted defaults 
after the page was once unloaded and if the back button happens to 
thereafter be used.

Tuxedo

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web