Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Nov 2010
    Thanked 2 Times in 2 Posts

    If the link clicked is not on domain.com show warning?


    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,

  2. #2
    Senior Coder
    Join Date
    Jun 2008
    New Jersey
    Thanked 259 Times in 256 Posts
    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.

  3. #3
    New Coder
    Join Date
    Aug 2012
    Kalamazoo, MI
    Thanked 0 Times in 0 Posts
    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.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts