View Full Version : If the link clicked is not on domain.com show warning?

07-31-2012, 01:46 PM

I'm not sure what language is best to achieve what I'm looking to accomplish. I would like, no matter where the link is, ie; posted in the forums, on a tutorial page or whatnot, a warning pops up in a dialogue box, alike the JQuery one.

This will happen if the website is not internal or the domain.com of the game this website is being created for. If the link is one of the above, the dialogue will simply warn them that anything which happens outside of this website and the games website which results in anything happening on the site I'm working on or in-game, we cannot be held responsibility.

Do you know how to do this, or know of any useful tutorials/downloads I have missed in search for how to do this? If your able to help, thank you in advice for any help and/or advice you give.

Best Regards,

07-31-2012, 04:04 PM
So you want it so when someone clicks an external link, to bring up a popup? Something that happens on the client end without needing to send data to the server? Then the only choice is Javascript.

When someone clicks a link, check the domain of that link to see if it matches one on a whitelist you set (your domain), and if it doesn't bring up a warning.

08-01-2012, 08:58 PM
Keleth is right, you have to do this via javascript, here is a quick example:

//get links
var nodes = document.getElementsByTagName("a"), i = nodes.length;

//get local host
var regExp = new RegExp("//" + location.host + "($|/)");

//test link if local or external
var href = nodes[i].href;
var isLocal = (href.substring(0,4) === "http") ? regExp.test(href) : true;
alert(href + " is " + (isLocal ? "local" : "not local"));

this code will test whether the link is local or external and alert the user with the answer. You can change this to activate the link if its local and alert only if it is external. All links NOT beginning with "http" or "https" are considered local.