Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Old 06-08-2010, 07:13 PM Prompt in JavaScript
sevamaster's Avatar
Experienced Talker

Posts: 35
Name: Basiy
Trades: 0
What i want is, when a user leaves or clicks back button there should be a prompt which asks him if he wants to visit another site. If he clicks yes then the page should be redirected. If clicks no then the browser closes or goes to back whatever the visitor has clicked. (x or back button)

But it should not happen when user submits the form or visits internal link.

please don't suggest me not to do this, i dont care if its irritating as its for my client so its my humble request to all the js pros to help me asap.
__________________

Please login or register to view this content. Registration is FREE
,
Please login or register to view this content. Registration is FREE
and
Please login or register to view this content. Registration is FREE
.
sevamaster is offline
Reply With Quote
View Public Profile Visit sevamaster's homepage!
 
 
Register now for full access!
Old 06-08-2010, 07:26 PM Re: Prompt in JavaScript
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,384
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
You can't

the only event (onbeforeunload) you could use, will trigger on EVERY action that will change the current location of the window, even to a page on the same site.


HTML Code:
<script language="JavaScript">
  window.onbeforeunload = confirmExit;
  function confirmExit()
  {
    return "You are about to leave this page.  If any changes you made may be lost.  Are you sure you want to exit this page?";
  }
</script>
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 06-11-2010, 09:50 PM Re: Prompt in JavaScript
Banned

Posts: 4
Name: lili
Trades: 0
Wow! I’ve never heard of this before and I think they’re awesome!
zxcvbnm0453 is offline
Reply With Quote
View Public Profile
 
Old 06-16-2010, 11:22 AM Re: Prompt in JavaScript
Banned

Posts: 1
Trades: 0
This is just some of the codes you can use to make prompts.if you are just not well equipped i recommend get a tutorial it would be better.


<script language="JavaScript">

window.onbeforeunload = confirmExit;
function confirmExit()
{
return "You are about to leave this page. If any changes you made may be lost. Are you sure you want to exit this page?";
}
</script>
Nwanko is offline
Reply With Quote
View Public Profile
 
Old 06-16-2010, 02:35 PM Re: Prompt in JavaScript
Extreme Talker

Posts: 246
Trades: 0
if you don't want this to happen on a button click or clicking a link you should be able to add the following:

onclick="window.onbeforeunload= function(){};"

This should overwrite the onbeforeunload event before the onbeforeunload event gets fired.

Hope this works, haven't tested it.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
stbuchok is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Prompt in JavaScript
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.15442 seconds with 12 queries