By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,353 Members | 1,247 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,353 IT Pros & Developers. It's quick & easy.

Reloading a page before to follow a link

P: n/a
Hello all,

I've a very simple problem that appears to don't have a simple
solution.
I've a (dynamically generated) page with a number of external links.
What I need is that if the user clicks on an external link, before
to reach the link, the current page gets reloaded.

My first try was the obvious:

window.location.reload();
window.location='...';

This works in Firefox but does not on IE.
My second try what something like:

window.onload=function() {window.location='...';};
window.location.reload();

but this does not work in Firefox nor IE, other browsers not tested.
How can I fix this?

It is just as fine if there is a way to reload the page after the user
press the BACK button of the browser.

But I want to spend some word about why I've this problem, maybe
I'm doing something wrong.

Well that's simple, if I change stuff in the page using Ajax, when
the user follow a link, and then go back with the BACK button of
the browser the page does not "remember" that it was updated
via Ajax.

Thank you very much for any help,

p.s. what still I didn't tried is to put the reload as body.onLoad
event
and use cookies to set a flag so that at the first load it will not be
reloaded (forever... in a loop), but when I leave the page I set
the cookie before to leave, then when I'm back the reload will happen,
deleting the cookie just before to reload. Is this an idiomatic
solution?
I may like more one without a cookie if possible.

Regards,
Salvatore

Feb 22 '06 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Hi Salvatore,

Seems like you are complicating things urself..
Call the below reload() function whereever required. To demonstrate
you, I have just called it in the OnUnload event..

Hope that this is what you have been working for :)

Chaitu..

<html>
<head>
<title>Wanna leave my site?? Huh!! No way</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<SCRIPT language="javascript">
function reload()
{
location = location=self.location
}
</SCRIPT>
</head>

<body bgcolor="#FFFFFF" text="#000000" onUnload="reload()">
<a href="http://www.google.com">click</a>
</body>
</html>

Feb 22 '06 #2

P: n/a
Salvatore Sanfilippo wrote:
I've a very simple problem that appears to don't have a simple
solution. I've a (dynamically generated) page with a number of
external links. What I need is that if the user clicks on an external
link, before to reach the link, the current page gets reloaded.


This is not at all possible (or reasonable). Given that an event is
retained from one execution context to the other, after the first one
was exited, which it should not, one scroll motion and your entire
concept blows up.
PointedEars
Feb 22 '06 #3

P: n/a
ch***********@gmail.com wrote:
<html>
<head>
<title>Wanna leave my site?? Huh!! No way</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<SCRIPT language="javascript"> ^^^^^^^^^^^^^^^^^^^^^^ function reload()
{
location = location=self.location ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ }
</SCRIPT>
</head>

<body bgcolor="#FFFFFF" text="#000000" onUnload="reload()"> ^^^^^^^^^^^^^^^^^^^ <a href="http://www.google.com">click</a>
</body>
</html>


It has been a while since I have read such utter nonsense here.
PointedEars
Feb 22 '06 #4

P: n/a
Hi Thomas,

He says its a dynamically generated page right!! Why can he not
assosiate the reload() function with OnClick event of the external
links at design time??

Just to know why you call my code nonsense.. :)

Thanks, Chaitu..

Feb 22 '06 #5

P: n/a
ch***********@gmail.com wrote:
Hi Thomas,
Hello. Please quote the minimum of what you are replying to
and provide attribution of quoted material:

<http://jibbering.com/faq/faq_notes/pots1.html#ps1Post>
<http://safalra.com/special/googlegroupsreply/>
He says its a dynamically generated page right!!
That does not matter here. The HTTP client does not care about
it, even if it knew about it. So does the user agent and the
client-side script engine.
Why can he not assosiate the reload() function with OnClick
event of the external links at design time??
The code posted is not executed at design time at all, therefore
the event listener is not assigned at design time.
Just to know why you call my code nonsense.. :)


Google for language="javascript". About the rest of your code:

| location = location=self.location

Those three expressions all refer to the same object and value. It is as
if you would assign x = x = x.

With the important difference that once something is assigned to the
`location' property of the Global Object (there is an implicit property
access here, through the scope chain), all the code that triggered it is
usually gone, as the execution context is associated with that Global
Object.

If it is not gone (which would be relying on unspecified _and_
undeterministic behavior), this would reload the document twice.
_With_ using the cache, so it would change (almost) nothing.
PointedEars
Feb 22 '06 #6

P: n/a
Sorry people,

The js function was intended to be :

function reload()
{
location =self.location
}

But this works with page onUnload event.
He said :

window.location.reload();
window.location='...'; works with Firefox but not with FF. the above
works with Firefox as well.

If in case some one wants to use it with page unLoad event whatever be
the link.. it doesnt allow..

Thanks for your replies Thomas..

Regards, Chaitu

Feb 22 '06 #7

P: n/a
Salvatore Sanfilippo wrote:
My first try was the obvious:
window.location.reload();
window.location='...';
This looks crazy ;]

You can reload by adding a url into the query string, something like:

window.location = 'url?redirectTo=' + newURL;

And after reloading you can check this variable and redirect if it's setted.
Well that's simple, if I change stuff in the page using Ajax, when
the user follow a link, and then go back with the BACK button of
the browser the page does not "remember" that it was updated
via Ajax.


This so-called "AJAX" is bad, you can see more mistakes here:
<URL:http://alexbosworth.backpackit.com/pub/67688>, but it's quite cool.

To solve your problem you can avoid caching, so the page will always be
reloaded. You also can check through the XMLHttpRequest if something
changed too and get the new stuffs, etc. But the solution that you
choosed above is really strange hehe ;]
--
Jonas Raoni Soares Silva
http://www.jsfromhell.com
Feb 22 '06 #8

P: n/a
ch***********@gmail.com wrote:
Sorry people,
No. Your further disregarding of posting guidelines is not excused.
The js function was intended to be :

function reload()
{
location =self.location
}
Which is still not reasonable, as it uses the cache.
But this works with page onUnload event.
For appropriate values of "works".
He said :

window.location.reload();
window.location='...'; works with Firefox but not with FF.
Pardon?
the above works with Firefox as well.
If it does, which is yet to be showed, that does not make it reasonable.
If in case some one wants to use it with page unLoad event whatever be
the link.. it doesnt allow..


In English, please.
PointedEars
Feb 23 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.