Note that there are some explanatory texts on larger screens.

plurals
  1. POChrome extension not supporting code?
    primarykey
    data
    text
    <p>I have finally perfected my extension for Chrome, after asking 2 questions here. I am making it for personal use, based on an example one from a tutorial site, and what my version is meant to do is take a query input from a user, go to Flickr's API and return 24 images by searching that query. I opened the page as, well, a page, and it works perfectly. But when I try to open it as an extension, whatever the user types in, the query term doesn't change. I have therefore come to the conclusion that either some code isn't supported in chrome extensions or I'm doing something horribly wrong. If the former is correct, could you please specify what I can and can't use in extensions (or link me to somewhere that has the answer)? Note: yes, I do know that server-side languages don't work altogether. If, however, it is I that is doing something stupid, please tell me and, if possible, give me a hand in fixing this. Thanks in advance for any help offered. The code is below:</p> <p>JS (popup.js):</p> <pre><code>var q = "cake"; //Default search term var req; function querySubmit() { oForm = document.forms["queryForm"]; oText = oForm.elements["query"]; q = oText.value document.getElementById("images").innerHTML = ""; req.open( "GET", "http://api.flickr.com/services/rest/?" + "method=flickr.photos.search&amp;" + "api_key=90485e931f687a9b9c2a66bf58a3861a&amp;" + "text=" + q + "&amp;" + "safe_search=1&amp;" + "content_type=1&amp;" + "sort=relevance&amp;" + "per_page=24", true); req.onload = showPhotos; req.send(null);} var req = new XMLHttpRequest(); req.open( "GET", "http://api.flickr.com/services/rest/?" + "method=flickr.photos.search&amp;" + "api_key=90485e931f687a9b9c2a66bf58a3861a&amp;" + "text=" + q + "&amp;" + "safe_search=1&amp;" + "content_type=1&amp;" + "sort=relevance&amp;" + "per_page=24", true); req.onload = showPhotos; req.send(null); function showPhotos() { var photos = req.responseXML.getElementsByTagName("photo"); for (var i = 0, photo; photo = photos[i]; i++) { var a = document.createElement("a"); a.setAttribute("href",constructImageURL(photo)); a.setAttribute("target","_blank"); var img = document.createElement("img"); img.setAttribute("src",constructImageURL(photo)); a.appendChild(img); document.getElementById("images").appendChild(a); } } function constructImageURL(photo) { return "http://farm" + photo.getAttribute("farm") + ".static.flickr.com/" + photo.getAttribute("server") + "/" + photo.getAttribute("id") + "_" + photo.getAttribute("secret") + "_s.jpg"; } </code></pre> <p>HTML (popup.html):</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Teh popup&lt;/title&gt; &lt;style&gt; body { min-width:357px; overflow-x:hidden; } img { margin:5px; border:2px solid black; vertical-align:middle; width:75px; height:75px; } &lt;/style&gt; &lt;!-- JavaScript and HTML must be in separate files for security. --&gt; &lt;script src="popup.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="images"&gt; &lt;/div&gt; &lt;form name="queryForm" onsubmit="querySubmit();return false" action="#"&gt; Search: &lt;input type='text' name='query'&gt; &lt;input type="submit" /&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>manifest.json:</p> <pre><code>{ "name": "Flickr image searcher", "version": "1.0", "manifest_version": 2, "description": "Searches images on Flickr wirtout opening another page.", "browser_action": { "default_icon": "icon.png", "default_popup": "results.html" }, "permissions": [ "http://api.flickr.com/" ] } </code></pre>
    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.
    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