[Javascript] location redirect

Roger Roelofs rer at datacompusa.com
Fri Nov 19 11:09:11 CST 2004


Uri,

I have done something similar to what I think you want.  Go to  
<http://www.mhvillage.com/Listing.php?key=35121> and click on the 'Map'  
button to see it in action.

The code is in the functions in  
<http://www.mhvillage.com/js/mobodomo.js>.  Reproduced below.  I stole  
the idea from an article, but I can't find the url for it at the  
moment.

---------  js   -------------
function tagExternalLinks() {
	var aTags = document.getElementsByTagName("A");
	for (var i=0; i < aTags.length; i++) {
		if ((typeof aTags[i].rel != "undefined") && (aTags[i].rel ==  
"external")) {
			aTags[i].onclick = doExternalClick;
		}
	}
}

function doExternalClick() {
	var Msg = "Following this link will take you away from mhvillage.com.   
\n";
	if ((this.title) && (this.tltle == "MapQuest Map")) {
		Msg += "The following map is compliments of MapQuest.  \n";
	}
	Msg += "To return to mhvillage.com, click the 'Back' button at the top  
of the window.  \n\n";
	Msg += "Click OK to leave mhvillage.com or Cancel to remain where you  
are.";
	return (confirm(Msg));
}
if( window.addEventListener ) {
	window.addEventListener("load", tagExternalLinks, false);
} else {
	if(window.attachEvent) {
		window.attachEvent("onload", tagExternalLinks);
	} else {
		window.onload = tagExternalLinks;
	}
}

On Nov 19, 2004, at 10:57 AM, Grinwald, Uri wrote:

> Hello
>  
> I have a unique codign question and was wondering if there was a  
> smarter way of performing the task at hand.
> I have a few links on my website that have URL whick take them to  
> external sites (opens new window)
>  
> I have been asked to create a pop up that informs the user that they  
> are leaving our site and then asks them if they want to proceed by  
> clicking OK or Cancel respectively.
>  
> The Cancel button closes the window with the following code:
>  
> <form><input type=button value="Cancel"  
> onClick="javascript:window.close();">
> </form>
>  
> The OK button I have attached a function that offers them one more  
> chance (confirm box) that they can cancel out of before redirecting.
>  
> Here is the function:
> function confirm_entry()
> {
> input_box=confirm("Are you sure you want to leave dundeeprecious.com  
> ?");
> if (input_box==true)
>  
> {
> document.location.href =  
> "http://www.tse.com/HttpController? 
> GetPage=QuotesViewPage&DetailedView=DetailedPrices&Language=en&QuoteSym 
> bol_1=dpm";
>  
> }
>  
> else
> {
> // Output when Cancel is clicked
> window.close();
> }
>  
> }
> -->
> </script>
>  
> My problem is that the initial page has actually three separate  
> external links so how can I change the code to take them to the  
> correct link based on the referrer URL?
>  
> Currently I would have to create three similiar pages and just change  
> the location.href code... there has to be an easier way right?
>  
>  
>  
>  
>  
>  
>  
> Uri Grinwald
> Web Designer
> Dynamic Mutual Funds
> 40 King Street West
> 55th Floor Scotia Plaza
> Tel: 416 365-2437
> Fax: 416 365-5602
>  
>   
> !DSPAM:419e1a6b231853896715110! 
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript
>
>
> !DSPAM:419e1a6b231853896715110!




More information about the Javascript mailing list