Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery use in Google Chrome Extensions
    primarykey
    data
    text
    <p>I am creating a Chrome extension that follows manifest 2 guidelines. I have worked hours on this and cannot figure out how to get jquery to run inside of the webpage so that I can use it to animate elements on the page. (Specifically using the slideUp() function)</p> <p>Here is the manifest.json</p> <pre><code>"manifest_version": 2, "icons": { "16": "images/16.png", "25": "images/25.png", "32": "images/32.png", "48": "images/48.png", "128": "images/128.png" }, "background": { "scripts": ["js/main.js", "js/jquery.min.js"] }, "options_page": "options/options.html", "permissions": [ "tabs", "unlimitedStorage", "https://maps.google.com/*", "https://maps.googleapis.com/*" ], "page_action": { "default_name": "Fullscreen", "default_icon": "images/128.png" } </code></pre> <p>Here is the main.js</p> <pre><code>// Called when the url of a tab changes. function checkForValidUrl(tabId, changeInfo, tab) { // If the letter 'g' is found in the tab's URL... if (tab.url.indexOf('maps') &gt; -1 &amp;&amp; tab.url.indexOf('google') &gt; -1) { // ... show the page action. chrome.pageAction.show(tabId); } }; // Listen for any changes to the URL of any tab. chrome.tabs.onUpdated.addListener(checkForValidUrl); chrome.pageAction.onClicked.addListener(function(tab) { chrome.tabs.executeScript(tab.id, {code: "document.getElementById('paneltoggle2').click(); $('gb').slideUp();"}); }); </code></pre> <p>Here is the options.html</p> <pre><code>&lt;html&gt; &lt;head&gt;&lt;title&gt;My Test Extension Options&lt;/title&gt;&lt;/head&gt; &lt;script src="options.js"&gt;&lt;/script&gt; &lt;body&gt; Favorite Color: &lt;select id="color"&gt; &lt;option value="red"&gt;red&lt;/option&gt; &lt;option value="green"&gt;green&lt;/option&gt; &lt;option value="blue"&gt;blue&lt;/option&gt; &lt;option value="yellow"&gt;yellow&lt;/option&gt; &lt;/select&gt; &lt;br&gt; &lt;div id="status"&gt;&lt;/div&gt; &lt;button id="save" onclick="save_options();"&gt;Save&lt;/button&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Here is the options.js:</p> <pre><code>// Saves options to localStorage. function save_options() { var select = document.getElementById("color"); var color = select.children[select.selectedIndex].value; localStorage["favorite_color"] = color; // Update status to let user know options were saved. var status = document.getElementById("status"); status.innerHTML = "Options Saved."; setTimeout(function() { status.innerHTML = ""; }, 750); } // Restores select box state to saved value from localStorage. function restore_options() { var favorite = localStorage["favorite_color"]; if (!favorite) { return; } var select = document.getElementById("color"); for (var i = 0; i &lt; select.children.length; i++) { var child = select.children[i]; if (child.value == favorite) { child.selected = "true"; break; } } } document.addEventListener('DOMContentLoaded', restore_options); document.querySelector('#save').addEventListener('click', save_options); function insert() { $('#gb').after("&lt;div id='hideGB' style='background: #DEDEDE; display:inline-block; border-bottom-left-radius:3px; border-bottom-right-radius:3px; padding:1px 10px 1px 10px; cursor:hand;'&gt;&lt;div style='direction: ltr; text-align: left; height: 21px; overflow: hidden; vertical-align: middle; width: 21px; position: relative; display: inline-block;'&gt;&lt;div id='hideGBimg' style='left: 0; top: -1329px; height: 2334px; position: absolute; width: 42px; content: url(http://ssl.gstatic.com/docs/common/jfk_sprite70.png);'&gt;&amp;nbsp;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;"); document.querySelector('#hideGB').addEventListener('click', change_hicon); } function change_hicon() { if (document.getElementById('hideGBimg').style.top == '-1329px') { document.getElementById('hideGBimg').style.top = '-1168px'; } else if (document.getElementById('hideGBimg').style.top == '-1168px') { document.getElementById('hideGBimg').style.top = '-1329px'; } } document.addEventListener('DOMContentLoaded', insert); </code></pre> <p>And here is the error I get:</p> <pre><code>Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self' chrome-extension-resource:". </code></pre> <p>Thanks so much for your time and help,</p> <p>Leinardo</p>
    singulars
    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.
 

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