Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi,
On my aspx page, I have a tab control.
In each tab I am loading an Iframe with URL. This Iframe URL is stored in a db table.
Each tab has its own Iframe.
Tabs are generated dynamically by reading a data in a table.
When focus is on Iframe and user presses back button, it tries to load previous url in Iframe and gives 404 error.
How can I handle this backspace button case?
Same thing happens when user click browser back button.

Is there any way to handle these two scenarios?

Any help appreciated.

What I have tried:

I tried capturing KeyCode on keydown event in javascript and set window.location.href to the same page.
This works well on parent page. But when focus is on tab content, I dont have any control over there.

Also for my parent page, I am disabling cache on Page Init event by
protected void Page_Init(object Sender, EventArgs e)
{
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.Now.AddSeconds(-1));
Response.Cache.SetNoStore();
}
Posted
Updated 17-Aug-16 0:06am
Comments
JayantaChatterjee 21-Jun-16 5:50am    
You can use JavaScript to replace browser History of your web page..
Using ClientScriptManager...
https://msdn.microsoft.com/en-us/library/system.web.ui.clientscriptmanager(v=vs.110).aspx
Richard Deeming 21-Jun-16 13:00pm    
How are you generating the iframes? If you're using something like:
frame.src = url;

you could try using:
frame.contentWindow.location.replace(url);
instead.

You can't. This is entirely a browser control and your code can't access them.

However, you could probably force the cache to expire to disable the browser back button as you've done. You could try using this JavaScript hack to prevent browsing back here: Disable Browser Back Button Functionality using JavaScript[^]
 
Share this answer
 
The way I handled keyboard backspace button is to return false on KeyDown event.
JavaScript
document.onkeydown = function (e) {
	try {
		// IF backspace button is pressed, do not redirect the url.
		// keycode for backspace - 8 

	    if (e.keyCode === keyCode.backSpace) {
			return false;
		}
	} catch (e) {
		return true;
	}
};
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900