Note that there are some explanatory texts on larger screens.

plurals
  1. POaddEventListener not triggering when used in a chrome extension
    text
    copied!<p>I'm trying to make a chrome extension that will search different cache databases for a given page. However, it's not working as I expect it to.</p> <pre><code>&lt;!DOCTYPE HTML&gt; &lt;html&gt; &lt;head&gt; &lt;script type="text/javascript"&gt; var x; var img = document.getElementsByTagName("img"); for(x in img) { img[x].addEventListener('click',openPage, false); } function openPage(event) { alert("clicked"); var e = event.target; switch(e.alt) { case "WayBack Machine": chrome.tabs.update(tab.id, { url: "http://wayback.archive.org/web/*/" + tab.url }); break; case "Google Cache": if(tab.url.substring(0, 5) == "http:") chrome.tabs.update(tab.id, { url: 'http://webcache.googleusercontent.com/search?q=cache:' + tab.url.substr(7) }); else if(tab.url.substring(0,6) == "https:") chrome.tabs.update(tab.id, { url: 'http://webcache.googleusercontent.com/search?q=cache:' + tab.url.substr(8) }); break; case "Yahoo Cache": // Need the yahoo cache url break; case "Bing Cache": chrome.tabs.update(tab.id, { url: "http://cc.bingj.com/cache.aspx?q=" + tab.url + "&amp;d=4572216504747453&amp;mkt=en-US&amp;setlang=en-US&amp;w=802790a9,218b61b8" }); break; case "Gigablast": chrome.tabs.update(tab.id, { url: "http://www.gigablast.com/get?q=" + tab.url + "&amp;c=main&amp;d=70166151696&amp;cnsp=0" }); break; case "CoralCDN": chrome.tabs.update(tab.id, { url: tab.url + ".nyud.net" }); break; default: // Webcite // Need to send a request, this won't do chrome.tabs.update(tab.id, { url: "http://webcitation.org/query" }); break; } } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;img src="Google Cache.png", alt="WayBack Machine" class="button" id="WayBack Machine" height ="40px" /&gt; &lt;img src="Google Cache.png", alt="Google Cache" class="button" id="Google Cache" height ="40px" /&gt; &lt;img src="Google Cache.png", alt="Yahoo Cache" class="button" id="Yahoo Cache" height ="40px" /&gt; &lt;img src="Google Cache.png", alt="Bing Cache" class="button" id="Bing Cache" height ="40px" /&gt; &lt;img src="Google Cache.png", alt="Gigablast" class="button" id="Gigablast" height ="40px" /&gt; &lt;img src="Google Cache.png", alt="CoralCDN" class="button" id="CoralCDN" height ="40px" /&gt; &lt;img src="Google Cache.png", alt="Webcite" class="button" id="Webcite" height ="40px" /&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>However, it does not even alert(); When I try the code in a jsfiddle.net, it works: <a href="http://jsfiddle.net/RZ2wC/" rel="nofollow">http://jsfiddle.net/RZ2wC/</a></p> <hr> <p>Here is my manifest.json:</p> <pre><code>{ "name": "gCache", "version": "1.1.5", "description": "View the Google Cache of a page", "browser_action": { "default_icon": "icon.png", "default_text": "Google Cache version of this page", "default_popup": "cacheList.html" }, "permissions": [ "tabs" ] } </code></pre> <hr> <p>Any help would be greatly appreciated. On this question and any bugs that you see in my code that I haven't gotten to yet. Many thanks!</p>
 

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