I have created a very simple function to check if the link is external or not.
Basically, if fetches the current Domain and checks it against the select link, if the URL is within the same domain, then we don't need a confirmation.
However if the URL is not within the Domain, we send a pop-up confirming they want to visit that site, if the cancel they stay on the current page.
Below is the function:
function exLinks(URL){
// Check the domain against the link.
// If the link is not within the current Domain, prompt the user.
if(!URL.indexOf(document.domain)!=-1) {
msg = "This is an external link, are you sure you wish to visit this site?"; // Pop-up message, for confirmation.
// If confirmed, redirect to the external website
if(confirm(msg)) {
window.location=URL;
}
} else {
// If the URL is within the same domain, no confirmation needed.
window.location=URL;
}
}
- function exLinks(URL){
- // Check the domain against the link.
- // If the link is not within the current Domain, prompt the user.
- if(!URL.indexOf(document.domain)!=-1) {
- msg = "This is an external link, are you sure you wish to visit this site?"; // Pop-up message, for confirmation.
-
- // If confirmed, redirect to the external website
- if(confirm(msg)) {
- window.location=URL;
- }
-
- } else {
- // If the URL is within the same domain, no confirmation needed.
- window.location=URL;
- }
- }
-
Here is a few samples on how to implement the links:
<a onClick="exLinks('http://www.Ozzu.com');" href="javascript:void();">www.ozzu.com</a><br>
<a onClick="exLinks('URL Here');" href="javascript:void();">Link Here</a><br>
<a onClick="exLinks('URL Here');" href="javascript:void();">Link Here</a>
- <a onClick="exLinks('http://www.Ozzu.com');" href="javascript:void();">www.ozzu.com</a><br>
- <a onClick="exLinks('URL Here');" href="javascript:void();">Link Here</a><br>
- <a onClick="exLinks('URL Here');" href="javascript:void();">Link Here</a>
-
If you need help still, PM me
