Refresh Previous Page

Hi,

I’m using this to go to the previous page


window.location=history.go(-2);

Is there any way I can go to the previous page and refresh it too. I’m doing this inside a Javascript function and cant use any html buttons. Here’s the complete function.


function RecModifiedAlert()
{
	alert('Record Modified!',0);
	window.location=history.go(-2);
}

Thanks for you help.

Have you tried window.location.reload() ?

I did try something like reload(history.go(-2)) and it didn’t work.

the problem is when you go back in the history - the browser re-renders the page (you get a brand new “load” of the page) - but it does not force a “refresh” of that page (forcing to go to the server).

There is a way to do this - but it is a hack.

first – in the page you are Going back FROM you can can add a parameter to the history result as follows. So you go pack to the same page - but with a new paramenter in the URL string.

var u = history.go(-1);
u += “?param=refresh”; // make this whatever you want
document.location = u; // go back - to a URL with the parameter added

Then in the page you go back TO - check for that parameter as follows, and refresh the page - but before you refresh - strip off the parameter - or the page will just keep refreshing over and over:


var href = document.location.href;
if(href.indexOf("?param=refresh") != -1)
{
     href = href.substring(0,href.indexOf("?param=refresh"));
    /* the line above strips off the parameter so refresh only occurs
        once otherwise the page would refresh over and over */
     document.location = href;
}

Hope that helps and good luck!

If you don’t mind the parameter still being there and you’re not in control of the page you want refreshed, you could place the current date/time there as a unique value to ensure the page refreshes each time you go back to it.

Do you not no which page they will be going back to? coz if u do u can just use windows.location.href=‘waterver.php’;

Thanks for the help everyone.

No I dont. I know the address of the page the user needs to be redirected to…But, the problem is that it is a dynamic page. The contents change based on the Serial number selected from a drop down box. So, I need to go back to the page the user originally came from and refresh it.

kburb23, Thanks for the code.I tried it and it seems to be the right way to go.
But, I’ve just discoverd a problem which leads to this question. Dosent history.go(-1) work after doing a form submit?
Because I get a “URL does not exist” error and the URL looks like this

http://…/undefined?param=refresh

If you don’t mind the parameter still being there and you’re not in control of the page you want refreshed, you could place the current date/time there as a unique value to ensure the page refreshes each time you go back to it.

pmw57, could you please explain this further. I’m kind of new to this.

Thanks!

My apologies, I’m mistaken. history.go() is a browser type of command. You can’t gain access to paths through the history.

What you can do though is to work with the document referrer.


location.href = document.referrer + '?date=' + new Date().valueOf();

oh I get it neat idea…Could you please tell me where I need to place this piece of code?
Thank you.

I suspect that you should use it to replace the window.location line from post #1

Ok I tried it…the page does go back but only the header and footer is diaplayed the middle part- the actual content is not. I do think the page refreshes because the time display on my footer is refreshed.

Pleeeease help me. This is driving me crazy.

hmmm. This is gona be very tricky. IRC i had to do something like this many years ago, but cnt think of it right now.

there is a issue with the post back. try this, change ur drop downs on that page to load the data as u want. then hit F5. It should ask u to post data again.

That is where the problem comes in wen the js goes back, as it needs to re-post the last form data.

U need it to refresh the page without that msg.

Am i correct? I will try and figure it out again for you, if thats the problem. It might not be that simple tho. Also very hard to help a situation like this where i dnt have the entire solution infront of me.

Yes that is kind of what I’m trying to do…But, I’m noticing that I have the same problem when I try to go back after a Submit without refreshing ie

location.href = document.referrer 

gives the same result as

location.href = document.referrer + '?date=' + new Date().valueOf();