0

我想通过单击一个按钮(通过 Kynetx 注入)打开一个新窗口,但我希望这个新窗口在 Kynetx 沙箱环境中运行。这是因为新窗口将有一个与 REST API 对话的按钮,我想避免浏览器同源策略。我还想修改这个新窗口的 DOM。

//code in Kynetx extension
ruleset a2031x3 {
meta {
    name "Open a new window (SO 12030281)"
    description << >>
    author "Steve Nay"
    logging off
}

dispatch { 

    domain "exampley.com"

    }

global { }

rule first_rule {
    select when pageview ".*" setting ()
    emit <|
        // Open a new window and write some content
        var newContent = 'some content';
        newWin = window.open();
        newWin.document.write(newContent);
    |>;        
 }
}

请帮忙。

4

1 回答 1

0

您需要将该 JavaScript 代码包装在一个emit块中,如下所示:

ruleset a000x0 {
    meta {
        name "Open a new window (SO 12030281)"
        description << >>
        author "Steve Nay"
        logging off
    }

    dispatch { }

    global { }

    rule first_rule {
        select when pageview ".*" setting ()
        emit <|
            // Open a new window and write some content
            var newContent = 'some content';
            newWin = window.open();
            newWin.document.write(newContent);
        |>;        
    }
}

这将打开一个您想要的弹出窗口,并且write()调用成功:

弹出窗口,

于 2012-08-20T23:09:39.387 回答