[Javascript] Need Javascript logic for going to homepage if the previous history not available
Paul Novitski
paul at juniperwebcraft.com
Mon Sep 1 09:21:25 CDT 2008
At 8/29/2008 07:39 PM, Rajaram Sahasranaman wrote:
>In my aspx page, I have two tabs. I have written a javascript in such a way
>that if the user clicks on first tab, it will go to the previous page
>visited and that will be the required behaviour which is working perfectly
>fine.
>
>Sometimes the previous history will not be available. In the sense, there is
>an option that the user can directly visit the page by making changes in the
>url without going to login and home page. In such a case, I need to show the
>user the home page. How will I do that? Can anybody provides any logic to me
>for this?
if (history && history.length > 1)
{
sDestination = 'index.php';
}
else
{
sDestination = 'somewhere-else.php';
}
It's always helpful to consult the source:
http://developer.mozilla.org/en/DOM/window.history
I don't know if testing for the existence of the history object is
really necessary since it appears to be created by default in current
browsers, but I might toss it in just in case the executing browser
doesn't support it so that "history.length > 1" doesn't crash the browser.
As always, a javascript navigation system like this should be backed
up by redundant or fall-back server-side navigation so that in the
absence of an operational javascript interpreter the page doesn't
break. Javascript is the icing, not the cake, and in my view should
not be relied upon to provide core functionality for publicly-accessible pages.
Regards,
Paul
__________________________
Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com
More information about the Javascript
mailing list