kareem_elzeiny Posted July 29, 2011 Share Posted July 29, 2011 Hello,In brief I'm using this Script whenever a visitor click an external link on my blog <script src='http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js' type='text/javascript'/><script type='text/javascript'>//<![CDATA[jQuery('a').each(function() {// Let's make external links open in a new window.var href = jQuery(this).attr('href');if (typeof href != 'undefined' && href != "" && (href.indexOf('http://') != -1 || href.indexOf('https://') != -1) && href.indexOf(window.location.hostname) == -1) { $(this).attr("target", "_blank"); if (href.search(/(bit.ly|google.com)/) == -1) { $(this).attr('href', "http://dstats.net/download/"+"?link="+href+"&"); } }});//]]></script> I need to add a random URL from a given list before the href ("http://www.url1.com/", "http://www.url2.com/", "http://www.url3.com/") $(this).attr('href', "http://dstats.net/download/"+"RANDOM URL FROM THE LIST"+"?link="+href+"&"); Any Ideas ??Regards,, Link to comment Share on other sites More sharing options...
JamesB Posted July 29, 2011 Share Posted July 29, 2011 Try this: var urls = ["http://www.url1.com/", "http://www.url2.com/", "http://www.url3.com/"];var key = Math.floor(Math.random()*urls.length);var url = urls[key];$(this).attr('href', "http://dstats.net/download/"+url+"?link="+href+"&"); Link to comment Share on other sites More sharing options...
kareem_elzeiny Posted July 30, 2011 Author Share Posted July 30, 2011 Try this:var urls = ["http://www.url1.com/", "http://www.url2.com/", "http://www.url3.com/"];var key = Math.floor(Math.random()*urls.length);var url = urls[key];$(this).attr('href', "http://dstats.net/download/"+url+"?link="+href+"&"); It works ,, Thanks Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.