One of our clients has asked for a pop up alert to come up when an external link is clicked. This is for some regulatory thing to say 'You are now leaving the site of…"
Anyone know how to do this?
The said link is the ‘Latest News’ HTML markup on the bottom right.
Apply Protaculous to the page. Choose prototype-packed from the Function picker. Click on the top Function Body button and paste in the following:
var here = window.location.hostname;
$$('a[href]').reject(function(elm){
return (elm.href.hostname == here);
}).invoke('observe', 'click', function(evt){
evt.stop();
var msg = 'You are about to leave this site.' +
"nn" +
'Are you sure you want to do that?';
if(confirm(msg)){
window.location.href = elm.href;
}
});
That should kink every outbound link on the page to display the confirmation dialog.
Walter
On Oct 29, 2012, at 10:40 AM, Graeme wrote:
Hi All,
One of our clients has asked for a pop up alert to come up when an external link is clicked. This is for some regulatory thing to say 'You are now leaving the site of…"
Anyone know how to do this?
The said link is the ‘Latest News’ HTML markup on the bottom right.
Not until I figure out what went wrong with it. Dave pointed out (correctly) that it doesn’t work yet. window.location.hostname is not working the way I thought it would. The basic premise is there, I just need to figure out what to do for the test that decides if a link is local or not.
var here = window.location.protocol + '//' +
window.location.hostname;
$$('a[href]').reject(function(elm){
return (elm.href.include(here));
}).invoke('observe', 'click', function(evt){
evt.stop();
var msg = 'You are about to leave this site.' +
"nn" +
'Are you sure you want to do that?';
if(confirm(msg)){
window.location.href = this.href;
}
});
Walter
On Oct 30, 2012, at 1:51 PM, Walter Lee Davis wrote:
Onbeforeunload fires before every page change. Same issue.
Walter
On Oct 30, 2012, at 1:22 PM, DeltaDave wrote:
What about a slightly different approach. I found this bit of jQuery
Sure, if you want to go through and add a rel attribute in Freeway to each external link, that’s another way to do it. In Prototype, it would be this simple:
Here’s one I wrote earlier that should trap all external links (links to _blank targets or absolute links) and pop a confirmation in front of the user before they go any further. Annoying, functional and lightweight. http://www.freewayactions.com/code/?f=Confirm+Outbound+Links.txt
Regards,
Tim.
On 30 Oct 2012, at 19:42, DeltaDave wrote:
All useful info - I am sure I will find a use for it at some point.