Create a new chrome tab / window from iframe

I currently have a problem with iframe ...

I have an iframe with a search field, and I want to do this search redirection when I'm in, creating a new tab / window

http://img51.imageshack.us/i/issuec.png/

So, to be clear, my request for the chrome google extension as a content script: overlay.js Then this one will be placed at the end of the current page on my "overlay.html" page.

So, the problem is that my .html is presented as an iframe, and I don’t see how I can redirect from this iframe.

overlay.html

<form id="searchForm" action="#" onsubmit="searchBoxRedirection(this)" method="post">
<img id="logo" src="images/extension.png" alt="Logo"></img>
<input type="search" value="" name="searching">
<input type="submit" value="Go !" /> 
</form>

overlay.js

var overlay= {
    init: function() {
        this.injectoverlay();
        //alert('Initialisation reussie');
    },

    injectoverlay: function() {
        var body = $('body'),
            overlayURL = chrome.extension.getURL("overlay.html"),
            iframe = $('<iframe id="YouroverlayFrame" src="'+overlayURL+'">');

            body.append(iframe);
            iframe.show();

        //alert('Injection reussie');
    }
}

Tool.js

function searchBoxRedirection(form)
{
    tabs.create({url:"www.yahoo.fr"});
}

manifest.json

{   

    "background_page" : "background.html",
    "browser_action" :
    {
        "default_icon" : "images/Extension.png"
    },
    "content_scripts": 
    [ {
      "all_frames": true,
      "css": ["css/overlay.css"],
      "js": ["js/overlay.js"],
      "matches": ["http://*/*"],
      "run_at": "document_start"
    } ], 
    "permissions" : ["tabs", "unlimitedStorage", "http://*/*"], 
    "name" : "MyOverlay",
    "version" : "1.1",
    "description" : "Sindar Overlay"
}
+3
source share
2 answers

Content-Scripts, API Chrome, chrome.extensions. *

, :

URL- -

  • , .
  • DOM

. :

  • . * API ( chrome.extension)
  • ,
  • , -
  • XMLHttpRequests

, , , , :

, , , - , chrome.tabs.create .

contentscript.js

chrome.extension.sendRequest({visit: "http://yahoo.fr"});

background.html

chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
  if (request.visit) {
    chrome.tabs.create({url: request.visit});
  }
  sendRepsonse({}); // Snub
});

Script:

<iframe src='iframe.html'></iframe>
<script type="text/javascript">
   function changeURL(url) {
 document.location=url;
   }        
</script>

IFrame :

 <a href="javascript:parent.changeURL('http://yahoo.fr');">Change to Yahoo</a>
+4

, , , ,

Content Script injects:

<iframe src='iframe.html'></iframe>
<script type="text/javascript">
   function changeURL(url) {
 document.location=url;
   }        
</script>
IFrame contains:

 <a href="javascript:parent.changeURL('http://yahoo.fr');">Change to Yahoo</a>
0

Source: https://habr.com/ru/post/1794660/


All Articles