nasekt Posted October 23, 2014 Share Posted October 23, 2014 I use [Fiddler](Understanding FiddlerScript ), Man in the middle proxy tool var regex = /TargetString/gi ;if (regex.match(URL) {var request_arr = new Array( "www.bing.com", "www.google.com", "www.yahoo.com", "www.sandbox.com");var random_url = request_arr[Math.floor(Math.random() * request_arr.length)]; Basically, The above code says, if the TargetString is found in URL, then redirect it to a random URL.What I need, For example:If TargetString is found in www.example.com/TargetString redirect to by picking a random URL from array list and NOT to use THAT URL in the futureThank you Link to comment Share on other sites More sharing options...
thescientist Posted October 23, 2014 Share Posted October 23, 2014 what's your question? what have you tried? Link to comment Share on other sites More sharing options...
nasekt Posted October 23, 2014 Author Share Posted October 23, 2014 If TargetString is found in www.example.com/TargetString redirect to by picking a random URL from array list. Now, how do I tell javascript to NOT pick the already picked URL? Link to comment Share on other sites More sharing options...
justsomeguy Posted October 23, 2014 Share Posted October 23, 2014 The easiest way would probably be to just remove it from the array after picking it. Arrays have a splice method you can use to remove elements. Link to comment Share on other sites More sharing options...
Hadien Posted October 23, 2014 Share Posted October 23, 2014 If the web page is redirected, how would splicing the array work? the page is no longer loaded cause you've just been redirected. now if that array was stored in a WebStorage object.... Which then you simply remove the url fro the arry as JSG says and then resave the array back into the session storage. Link to comment Share on other sites More sharing options...
kodejuice Posted October 26, 2014 Share Posted October 26, 2014 (edited) //check this outvar target = "TargetString";var condition = (window.location.href.toLowerCase().indexOf(target.toLowerCase()) > -1 )?"random": "no-random" ;if (condition === "random") {var request_arr = ["www.bing.com", "www.google.com","www.yahoo.com","www.sandbox.com"];var random_url = request_arr[Math.floor(Math.random() * request_arr.length)];var cook = "url="+random_url+";expires=December 25, 2060;path=/";document.cookie = cook;var url = document.cookie.split(";");for(i=0;i<url.length;i++){if(url == random_url){random_url = request_arr[Math.ceil(Math.random() * request_arr.length )];break;} else{window.location = random_url;}}} else{//target string not found in url.} Edited October 26, 2014 by kodejuice Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now