Reloading a page before to follow a link

  • Thread starter Salvatore Sanfilippo
  • Start date
S

Salvatore Sanfilippo

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
 
C

chaitu.madala

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>
 
T

Thomas 'PointedEars' Lahn

Salvatore said:
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
 
T

Thomas 'PointedEars' Lahn

<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
 
C

chaitu.madala

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..
 
T

Thomas 'PointedEars' Lahn

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>
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
 
C

chaitu.madala

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
 
J

Jonas Raoni

Salvatore said:
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 ;]
 
T

Thomas 'PointedEars' Lahn

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,233
Members
46,820
Latest member
GilbertoA5

Latest Threads

Top