Note that there are some explanatory texts on larger screens.

plurals
  1. PORandom URL redirect from array
    primarykey
    data
    text
    <p>/** * Political Animals * contentscript.js is loaded on each page(s) listed in manifest.json * This plugin replaces all the images on the website of news sites with pictures of * animals in suits, as a commentary on what the news has become. Made for Web 2 * November 20, 2013 */</p> <p>//Random Image array</p> <pre><code>var arrayImg = ['http://www.whattofix.com/images/PoliticalAnimal.jpg','http://www.fubiz.net/wp-content/uploads/2013/03/Fashion-Zoo-Animals26.jpeg','http://img1.etsystatic.com/016/1/7647665/il_340x270.411173311_ojy5.jpg','http://ny-image0.etsy.com/il_fullxfull.85564656.jpg','http://afraidofmice.com/blog/wp-content/uploads/2011/08/berkleyill.jpg','http://elizabethmarshallgalleryblog.files.wordpress.com/2011/05/etsy-panda-for-blog1.jpg','http://moesewco.typepad.com/.a/6a00e5500684b488330120a5c7cf3a970c-300wi','http://ih3.redbubble.net/image.13276877.5059/flat,800x800,070,f.u1.jpg','http://www.tildeshop.com/blog/wp-content/uploads/2012/09/SeaLionFemale-21.jpg']; </code></pre> <p>//redirect</p> <pre><code>var acceptedWebsites =['www.cnn.com', 'www.nytimes.com', 'www.latimes.com', 'www.washingtonpost.com', 'www.nbcnews.com', 'www.foxnews.com']; var currentUrl = document.location.href; var referrer = currentUrl.match(/:\/\/(.[^/]+)/)[1]; </code></pre> <p>//Making sure the code does what I want it to. As long as the link shows a number greater than -1, then the site extension is working console.log(referrer); console.log(acceptedWebsites.indexOf(referrer));</p> <p>//var url = acceptedWebsites[Math.floor(Math.random()*acceptedWebsites.length)]; //document.location.href = url;</p> <p>// image source goes through the following script function $('img').each(function(){</p> <p>// creating the randomizing</p> <pre><code>var random = arrayImg[Math.floor(Math.random()*arrayImg.length)]; //Takes the current array and applies the source with the random function $(this).attr('src', random); //removing the stretch var theWidth = $(this).width(); var theHeight = $(this).height(); if (theWidth &lt; theHeight) { $(this).height(150); } else { $(this).width(150); } }); </code></pre> <p>//alert ("Go to any of the follow websites: fox.com, nbc.com, nytimes.com, latimes.com, or cnn.com");</p> <p>I have this array in javascript. I want to have it so that the user is automatically redirected to one of the links from the array, possibly randomly. I don't know if I can do this in javascript. I am using this for a chrome extension, so I don't know if I can use php.</p> <p>These are fantastic answers, except they constantly redirect. I want it so that they are just redirected to one from the array once, not constantly redirect. </p> <p>**Edit 2: I added my whole code because something is causing there to be a constant redirect instead of only once.</p> <p>**Edit 3: I updated my code. The console.log proves that my new variables work and do ==-1. How can I use them to redirect?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload