0

我目前对 iframe 有一些问题。

我有一个带搜索框的 iframe,我想在单击 go 时进行此搜索框重定向...但是没有任何效果,我不明白我必须做什么...

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

编辑:24/02/2011 所以要清楚,我的谷歌浏览器扩展调用作为内容脚本:overlay.js 然后这个将放在当前页面的末尾我的“overlay.html”页面。

所以问题来自我的 .html 被表示为 iframe,我看不到如何从这个 iframe 重定向

覆盖.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>

覆盖.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');
    }
}

工具.js

function searchBoxRedirection(form)
{
    //alert(form.searching.value);
    //tabs.create({url:"www.yahoo.fr"});
    //parent.chrome.tabs.create({url: "http://blackweb20.com/"});
    //parent.location.href='www.yahoo.fr';
    //chrome.tabs.update({url:"http://www.siteduzero.com",selected:true});

    //chrome.windows.create({url:"http://www.siteduzero.com"});
}

清单.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"
}

更新

我通过使用找到了部分答案:

function searchBoxRedirection(form)
{
    window.top.location.href = "http://search.yahoo.com/search?p=" + form.searching.value;
}

但是对于创建新选项卡或新窗口,它不起作用......

4

1 回答 1

1

这个问题与以下内容完全相同(逐字逐句): Create a new chrome tab/window from a iframe

总而言之,您有两种选择:

  • 使用消息来重定向页面。
  • 在 iframe 中调用“父级”进行重定向。
于 2011-02-25T23:17:22.353 回答