Go Back   CodingForums.com > :: Client side development > General web building

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-31-2012, 12:46 PM   PM User | #1
MrTIMarshall
Regular Coder

 
Join Date: Nov 2010
Posts: 347
Thanks: 44
Thanked 1 Time in 1 Post
MrTIMarshall is an unknown quantity at this point
If the link clicked is not on domain.com show warning?

Hello,

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,
Tim
MrTIMarshall is offline   Reply With Quote
Old 07-31-2012, 03:04 PM   PM User | #2
Keleth
Senior Coder

 
Join Date: Jun 2008
Location: New Jersey
Posts: 2,354
Thanks: 45
Thanked 247 Times in 244 Posts
Keleth is on a distinguished road
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.
Keleth is offline   Reply With Quote
Old 08-01-2012, 07:58 PM   PM User | #3
TylerB
New Coder

 
Join Date: Aug 2012
Location: Kalamazoo, MI
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
TylerB is an unknown quantity at this point
Keleth is right, you have to do this via javascript, here is a quick example:

Code:
//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
while(i--){
    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.
TylerB is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:41 AM.


Advertisement
Log in to turn off these ads.