我想通过单击按钮(通过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);
|>;
}
}
请帮忙。
答案 0 :(得分: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()
调用成功: