Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get and pass URL to popup

Status
Not open for further replies.

HenryAnthony

Technical User
Feb 14, 2001
358
US
Hi,

When someone clicks a link that links to a page outside of our site, I need a popup window that warns that the link is outside of our site. Is it possible to develop a script that, when the link is clicked:

1. "Grabs" the URL of the link.
2. Opens a popup that includes a link to the "grabbed" URL.

I need to do this because I have a great many of these links and want to avoid having to create separate popups for each URL. Any comments are greatly appreciated.

Thank you,
Henry
 
Add this script to head of your html;

Code:
<script>
var myHome="[URL unfurl="true"]http://localhost/"[/URL]

function controlLinks()
{
	for(var i=0;i<document.links.length;i++)
	{
var a = document.links[i];
if(a.href.substring(0,myHome.length)!=myHome)
{
	a.href="javascript:confirmNavigate('"+a.href+"')";
}
	}
	
}
function confirmNavigate(url)
{
	if(confirm('The link you\'ve just clicked is an outbound link;\n['+url+']\n\nIf you click, you\'ll leave from this site.\nDo you confirm?'))
	{
document.location.href=url;
	}
}
</script>

And add an onload event to the body element of your html;
Code:
<body onload="controlLinks()">

Please do not forget to modify myHome variable to reflect your domain.
This script will cycle thru the links on your site and will check whether their href's start with your home domain address. If not, it'll replace the href with a javascript function which requires a confirmation from user to navigate away.

I used a simple js confirm box, but of course you can change the confirmNavigate function to open another window and take the confirmation from there...

Hope this helps,

regards
@li
 
captainPlus,

Wow! I was hoping to get some general direction and you provided the code. Thank you so much! It will take me a day or so to try this before I post back.

Regards,
Henry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top