/    Sign up×
Community /Pin to ProfileBookmark

Hi,
How to control the navigator’s back button ?
It is possible to redirect the page where i want or stop the session when the user press on back button ?
Thank you,

to post a comment
JavaScript

8 Comments(s)

Copy linkTweet thisAlerts:
@Phil_KarrasFeb 26.2003 — At one time we could do just about anything to the array of URLs in the previous var, unfortunately I'm not sure we still can. Things were changed when security issues came to light and so all browsers & JS changed to protect previous URLs from being printed, etc.

Now, as to controlling the back arrow button uses something like the JS method:

[b]history.go(-1);[/b]

You can make your own buttons that can go back or forward any number of places, as in:

[b]history.go(-3);[/b] - back three URLs, if they exist.

Now, as to loading the array of past URLs? Again, I don't think we have that control any longer.

Anyone else know differently?

There's the var: [b]document.referrer[/b]

and then there was the array (I believe): [b]history.previous[/b]
Copy linkTweet thisAlerts:
@jean-baptisteauthorFeb 27.2003 — Thanks for you response.

If I include/understand well, it there not JavaScript event which makes it possible to control the back button of navigator. However, in certain banking sites when you click on the back button during a session the site you log off automatically. Any idea?
Copy linkTweet thisAlerts:
@dabushFeb 27.2003 — javascript can not CONTROL the back button, it can just USE it.
Copy linkTweet thisAlerts:
@Phil_KarrasFeb 27.2003 — OK, while we can not control the action of the browser back arrow button (BA? we can control what happens when you leave our page.

[b]onBlur[/b] fires whenever focus moves to another page, or the BAB is used, also I believe there's onUnload() which fires when the user tries to leave your page:
<i>
</i>&lt;body onUnload='OutOfHere();'&gt;

Where [b]OutOfHere()[/b] is a function called when this page is exited. (The BAB is pressed.)
Copy linkTweet thisAlerts:
@jean-baptisteauthorFeb 27.2003 — Ok this code seems work :

vbscript :

<SCRIPT LANGUAGE="VBScript" >

<!--

sub OutofHere()

...

end sub

-->

</SCRIPT>

<BODY Language="VBS" onUnload = "OutofHere">

javascript :

<SCRIPT LANGUAGE="JavaScript" FOR="window" EVENT="onunload">

...


</SCRIPT>

Thank you
Copy linkTweet thisAlerts:
@Phil_KarrasFeb 27.2003 — I must admit that I have never seen "[b]sub[/b]" used in JavaScript. The correct form (as supported by the w3c standard) is:
<i>
</i>&lt;SCRIPT LANGUAGE="VBScript" &gt;
&lt;!--
function OutofHere() {
// code goes here
}
--&gt;
&lt;/SCRIPT&gt;
Copy linkTweet thisAlerts:
@dabushFeb 27.2003 — hence the line

&lt;SCRIPT LANGUAGE="VBScript"&gt;
[b]Sub[/b] is a part of VBScript.

Phil, you are correct, it is NOT JavaScript, and therefore jean, you are posting in the wrong forum (although you can continue with this thread if you want to learn how to do it in JavaScript).
Copy linkTweet thisAlerts:
@Phil_KarrasFeb 28.2003 — Right, thanks, I hadn't even looked at the script tag.
×

Success!

Help @jean-baptiste spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...