Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Since your using <a href="http://code.google.com/chrome/extensions/content_scripts.html" rel="nofollow">Content-Scripts</a> you cannot call any Chrome API except a few chrome.extensions.*</p> <p>Here are some examples of what content scripts can do:</p> <h1>Documentation Quote</h1> <blockquote> <p>Find unlinked URLs in web pages and convert them into hyperlinks'</p> <ul> <li>Increase the font size to make text more legible</li> <li>Find and process microformat data in the DOM</li> </ul> <p>However, content scripts have some limitations. They cannot:</p> <ul> <li>Use chrome.* APIs (except for parts of chrome.extension)</li> <li>Use variables or functions defined by their extension's pages</li> <li>Use variables or functions defined by web pages or by other content scripts</li> <li>Make cross-site XMLHttpRequests</li> </ul> </blockquote> <p>Now to do what you want, you need to goto a link, you have two choices:</p> <ol> <li>Use <a href="http://code.google.com/chrome/extensions/messaging.html" rel="nofollow">Messaging</a> to redirect the page.</li> <li>Call "parent" within the iframe to do a redirect.</li> </ol> <h1>Messaging approach</h1> <p>Messaging is simple, all you do is send a request to the extension which will <code>chrome.tabs.create</code> the new page.</p> <p><strong>contentscript.js</strong></p> <pre><code>chrome.extension.sendRequest({visit: "http://yahoo.fr"}); </code></pre> <p><strong>background.html</strong></p> <pre><code>chrome.extension.onRequest.addListener(function(request, sender, sendResponse) { if (request.visit) { chrome.tabs.create({url: request.visit}); } sendRepsonse({}); // Snub }); </code></pre> <h1>Parent approach</h1> <p><strong>Content Script injects:</strong></p> <pre><code>&lt;iframe src='iframe.html'&gt;&lt;/iframe&gt; &lt;script type="text/javascript"&gt; function changeURL(url) { document.location=url; } &lt;/script&gt; </code></pre> <p><strong>IFrame contains:</strong></p> <pre><code> &lt;a href="javascript:parent.changeURL('http://yahoo.fr');"&gt;Change to Yahoo&lt;/a&gt; </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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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