By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,821 Members | 1,092 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,821 IT Pros & Developers. It's quick & easy.

Getting URL

P: 5
I was wandering if someone tryped a URL to live a page

can i have a alert saying

"you are going to XX-PageName-XX"


Thanks
Feb 6 '07 #1
Share this Question
Share on Google+
4 Replies

acoder
Expert Mod 15k+
P: 16,027
Welcome to The Scripts.

I don't think that is possible. If the user decides to leave the page of their own accord by typing the URL in the address bar, then you should have no control over that.

What you can do is control the links on your own page. They can all run some javascript which displays the alert and then transfers the user to the new page.
Feb 6 '07 #2

P: 18
You can trap the onunload event in Firefox and do it using some very Firefox-specific code, but otherwise it is impossible. It opens up a whole can of worms with privacy anyway.
Feb 7 '07 #3

dmjpro
100+
P: 2,476
yes he is right ...
try this code..................
Expand|Select|Wrap|Line Numbers
  1. <body onunload = test()>
  2. function test()
  3. {
  4.  alert('Page navigation is not allowed');
  5.  document.location.href = the_previous_URL;
  6. }
Code in tags - moderator

best of luck

i am online
Feb 8 '07 #4

acoder
Expert Mod 15k+
P: 16,027
try this code..................
Expand|Select|Wrap|Line Numbers
  1. <body onunload = test()>
  2. function test()
  3. {
  4.  alert('Page navigation is not allowed');
  5.  document.location.href = the_previous_URL;
  6. }
That is bad practice - preventing the user from leaving a page. The most you should do is ask for confirmation ("Are you sure you wish to leave this page?") though I disagree with that too unless you have a web application and the user has unsaved changes.
Feb 8 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.