[英]Open and control new window in KRL/Kynetx
I want to open a new window by clicking on a button (which is injected via Kynetx), but I want this new window to run in the Kynetx sandbox enviornment. 我想通过点击按钮(这是通过Kynetx注入)来打开一个新窗口,但我想这个新窗口中Kynetx沙箱enviornment运行。 This is because the new window will have a button which talks to a REST API, and I want to avoid browser same origin policy.
这是因为新窗口将具有一个与REST API对话的按钮,并且我想避免使用浏览器相同的原始策略。 I will also want to modify the DOM of this new window.
我还将要修改此新窗口的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);
|>;
}
}
Please help. 请帮忙。
You need to wrap that JavaScript code in an emit
block, like this: 您需要将该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);
|>;
}
}
That will open a popup window like you want, and the write()
call succeeds: 这将打开您想要的弹出窗口,并且
write()
调用成功:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.