Multiple redirect

I have a redirect script in some of my pages that connect with a single link.

I wonder if it is possible to have several links within the same scrupt, avoiding having to duplicate it each time

<a id="anchor" href="/redirect/index.php?id=Link1" target="_blank" rel="nofollow">
<script>

function _Link($a) {
	if(!navigator.userAgent.match(/Version\/[\d\.]+.*Safari/)) {
		document.getElementById($a).click();
	} else {
		var $e = document.createEvent('MouseEvents');
		$e.initMouseEvent('click', true, true, window);
		document.getElementById($a).dispatchEvent($e);
	}
}
</script>
<img src="An Image"></a>

Does this help?
http://codepen.io/ryanreese09/pen/XbWJBr

This assumes you are loading jquery.

You basically can just give each of those external links a class and just assign each to an event listener which runs the same function. You can modify what the function does and you can do this without jquery also but it’ll be lunkier.

Hi, that’s Chinese to me!

I’ve never touched JQuery. That little script JS I believe redirects an external link via an internal folder. It works well.

Now, I have a page with 28 external requests and taht’s far too much. I want to, at least, make them internal requests. That php thing solves the problem, but I wonder if I could use the js script to do the same.

with php i ahve to create a small file for each redirect; with the js script I would only need to add a line of url to the file that contains them all.

As I said it is working in my India page.

PS - Well, I wouldn’t mind trying your code above. I hadn’t looked at the html and the js" Laziness, I suppose…

Well Javascript can be disabled so it’s not a fullproof option…are you fine with that?

I’m in your very capable hands…JQuery here I come!!!

Have a look at the page to see what my problems is : India

LATER

With the php file I need 28 files and 28 internal requests. If I got all the urls in the same file, then I guess that the 28 requets would be reduced to 1 as the (whover GETs the requests) would know that the file has already been called. Is that how it works?

Having spent some time reading about the problems Js scripts create when users disable the function, I realize now that JQuery is jsscript under a disguise and there fore would present the same problem. So, what id the solution when httml/css cannot do the job?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.