469,602 Members | 1,747 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,602 developers. It's quick & easy.

Getting URL

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
4 1210
acoder
16,027 Expert Mod 8TB
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
UniDyne
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
2,476 2GB
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
16,027 Expert Mod 8TB
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.

Similar topics

5 posts views Thread by Francis Bell | last post: by
4 posts views Thread by R.Manikandan | last post: by
reply views Thread by guiromero | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.