简体   繁体   English

iframe重定向

[英]Iframe Redirection

I'm currently have some issue with an iframe. 我目前在使用iframe时遇到问题。

I have my iframe with a searchbox and i want to make this searchbox redirection when i click on go... But nothing works and i can't understand what i have to do... 我的iframe带有搜索框,我想在单击“转到”时进行此搜索框重定向...但是没有任何效果,我无法理解我该怎么做...

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

EDIT : 24/02/2011 So to be clear, my google chrome extension call as a content script : overlay.js Then this one will put at the end of the current page my "overlay.html" page. 编辑:2011年2月24日所以要清楚一点,我作为内容脚本的Google chrome扩展程序调用:overlay.js然后这将放在当前页面的“ overlay.html”页面的末尾。

So the problem come from that my .html is represented as a iframe and i don't see how i can redirect from this iframe 所以问题出在我的.html被表示为一个iframe而我看不到如何从该iframe重定向

overlay.html 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 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 Tool.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"});
}

manifest.json 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"
}

Update 更新资料

I've find a part of the answer by using : 我使用以下方法找到了答案的一部分:

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

But for the creation of new tab, or a new window it didn't work... 但是对于创建新标签或新窗口来说,它不起作用...

This question is the exact duplicate (word by word) of: Create a new chrome tab/window from a Iframe 该问题与以下内容完全相同(逐词): 从iframe创建新的chrome标签/窗口

To summarize, you have two choices: 总而言之,您有两种选择:

  • Use Messaging to redirect the page. 使用消息传递来重定向页面。
  • Call "parent" within the iframe to do a redirect. 在iframe中调用“父级”进行重定向。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM