Log in

View Full Version : warn before navigating away from your website


sailnet
12-12-2009, 12:07 PM
a loser showed up on one of my forums yesterday and posted a link to a hacked website in order to propogate his spyware and a few of my members fell for it.

perhaps this can be done with some javacript, I'm not sure but I'd like to be able to warn people when they click on a link within a thread to check if the destination is off of my site and let them know we have no control over others site and the site might be dangerous.

ideas?

thanks in advance.

Jeff

kh99
12-12-2009, 12:42 PM
Well you can do something like:

<a onclick="return confirm('Danger! You are going away now.\n\nAre you sure?')" href="http://cnn.com">Dangerous Site</a>


and it will pop up one of those "OK Cancel" boxes. But that's the easy part, I think. It's a little harder to figure out how to get it in to any link someone posts.

sailnet
12-12-2009, 12:50 PM
Well you can do something like:

<a onclick="return confirm('Danger! You are going away now.\n\nAre you sure?')" href="http://cnn.com">Dangerous Site</a>


and it will pop up one of those "OK Cancel" boxes. But that's the easy part, I think. It's a little harder to figure out how to get it in to any link someone posts.

thanks but the code must encapsulate all information in postbit and detect foreign urls from my url. I do not want to warn people going to other urls on my own website.

here's a piece of generic code I found, but it warns on every click and I need to somehow modify it so that it can determine the destination domain, then compare it to my domain and only show the message of the domain names are different.
<script>

window.onbeforeunload = function (evt) {
var message = ‘Are you sure you want to leave?’;
if (typeof evt == ‘undefined’) {
evt = window.event;
}
if (evt) {
evt.returnValue = message;
}
return message;
}

</script>

ChopSuey
12-12-2009, 05:57 PM
Should have that, thing like MySpace its a bit better.
MSPLINKS thingy.