0

I am looking at having a alert style box show up when a user tries to leave the page but I what I wanted to do is have a share link in the alert style box

I have read this ticket javascript before leaving the page and now am unsure if this is possible.

I realise this will run

$(window).bind('beforeunload', function(){
 alert("hi");
});

Now I know you cannot add links to an alert window so am trying to get round this another way but cant think of how i would display a alert/popup before going to another page that has a link in

Can anyone suggest anything - is there a plugin that might do this?

Community
  • 1
  • 1
Dan
  • 1,295
  • 2
  • 22
  • 46
  • So you need to show a link in `alert box`? – Rohan Kumar Nov 14 '13 at 05:25
  • you cant see http://stackoverflow.com/questions/276660/how-can-i-override-the-onbeforeunload-dialog-and-replace-it-with-my-own – Dev Nov 14 '13 at 05:26
  • so dev its not possible? – Dan Nov 14 '13 at 05:33
  • Its better you not do even if u do a hack as if you find a bug and use it to do it one they they will fix it and you will be again at same point. This is a security risk suppose i want to close a tab and in code you opne new popups or do malicious things???? So browserts dont allow it. If user wants to go they are allowed u can use standard window.onbeforeunload = function() { return 'You have unsaved changes!'; } if you like – Dev Nov 14 '13 at 05:35

2 Answers2

1

Its better you not do even if u do a hack as if you find a bug and use it to do it one they they will fix it and you will be again at same point. This is a security risk suppose i want to close a tab and in code you opne new popups or do malicious things???? So browserts dont allow it. If user wants to go they are allowed u can use standard

window.onbeforeunload = function() { return 'You have unsaved changes!'; } 

if you like So try this. istead of custom things.

DEMO

Dev
  • 6,628
  • 2
  • 25
  • 34
0

You cannot add links to an alert window. What you could do is use a jQuery Plugin like http://jqueryui.com/dialog/#default and call it within beforeunload function.

HTML

<div id="dialog" title="My Link">
 <a href="#">My Link</a>
</div>

jQuery

$(window).bind('beforeunload', function(){
 $( "#dialog" ).dialog();
});

OR if don't want to use jQuery you could use a window.open eg: http://www.quirksmode.org/js/popup.html

Chamara Keragala
  • 5,627
  • 10
  • 40
  • 58
  • according to this - http://stackoverflow.com/questions/276660/how-can-i-override-the-onbeforeunload-dialog-and-replace-it-with-my-own it is not possib;e – Dan Nov 14 '13 at 05:34