Showing posts with label Browsers. Show all posts
Showing posts with label Browsers. Show all posts

Wednesday, January 21, 2009

Handle back button of the browser

The "Back" browser button cannot be actually disabled by a web application as the browser security will not allow this.
If we want user to stay on the same page, even if user presses back button, then we can use javascript to achieve this.

<script type="text/javascript" language="javascript">
function Goback()
{
    //window.history.go(+1); 
    window.history.forward();
}
</script>

<body onload="Goback();">

This method will always redirect to the user on the current page itself.

For example, user is on page 1 and user goes to Page 2. Now from page 2 if user press back button of the browser then user will be redirect to the page 2 itself.

window.history contains the collection of the page visited by the user for particular browser session.
window.history.go(+1) and window.history.forward(); are same.

But if we want to display web page expired warning on the click of back button, then we must allow the browser to cache the page. This can be achieved by ASP.NET

/*To not to store the page in cache.*/


Response.ExpiresAbsolute = new DateTime(1900, 1, 1);
Response.Cache.SetCacheability(HttpCacheability.NoCache);

But one problem with this approach is that this will only work when there are some dynamic content in the page. i.e. change any combo or dropdown box value and then try to press back button.

If you can find out better solution then this please let me also know.

Enjoy...



Saturday, September 27, 2008

Firefox 3.0 now supports showModalDialog()


Javascript function window.showModalDialog() is used to create a modal dialog box that displays the specified HTML document. A modal dialog box, is kind of dialog box which retains the focus while open. The user cannot switch back to parent windows until the dialog box is closed.

This works fine in Internet explorer 4.0 and later version of IE but with Firefox 2.0 or below version it was not working. But there is a good news now that Firefox 3.0 supports showModalDialog() function.


Check out this link..


Test this page in Firefox 2 and Firefox 3



Chrome (Google's new browser) also supports showModalDialog().


Enjoy.....
Virendra Dugar
back to top