Geeks With Blogs
kazim mehdi

SCENARIO

I have page that was hosted inside the iframe and I want to redirect the parent window when a user click a button inside the child page.

For that I added the following code in the Button’s click event as I have to execute some server side code before redirecting.

 

Page.ClientScript.RegisterStartupScript(this.GetType(), RedirectKey, string.Format("window.top.location.href = ‘http://google.com’;", url), true);

 

PROBLEM

Above mentioned code worked great but when the user used the browser’s back button to go back to the previous page. It went there for a moment and

redirect to the location that I put inside the above javascript.

 

SOLUTION

I googled and search specifically on the stackoverflow and found the similar post and thanks peter-bailey he post the solution here. And the solution is using replace method

instead of just setting href.

 

top.location.replace it didn’t produce history.

Page.ClientScript.RegisterStartupScript(this.GetType(), RedirectKey, string.Format("top.location.replace('http://google.com');", url), true);
Posted on Friday, June 10, 2011 11:18 AM asp.net , Javascript | Back to top


Comments on this post: Remove/Disable javascript when using browser's back button

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © kazim sardar mehdi | Powered by: GeeksWithBlogs.net