我为网站创建了Greasemonkey脚本.脚本的作用是在页面末尾添加div.
document.body.insertBefore(myDiv, document.body.firstChild);
Run Code Online (Sandbox Code Playgroud)
但现在该网站为google-ads添加了一个iframe,结果我的div也出现在iframe中,这不是我想要的.
如何停止影响iframe的脚本?
我想知道你是否可以只针对iframe执行Greasemonkey执行,而不是它的父窗口.父窗口是域A,iframe是域B,脚本中的include是@include http://domain-B.com/path/*.
我不需要与父母进行任何互动.我已经尝试了几次没有成功.是否存在阻止某人针对iframe执行的跨域限制?
PS:iframe有JS代码阻止它作为顶部窗口加载.
在下面的 HTML 模型中,嵌套的 iframe 来自不同的子域。这会导致诸如错误之类的消息:权限被拒绝访问属性“文档”
<html>
<head>
<title></title>
</head>
<body>
<div>
<iframe id="outer_iframe_1" src="https://subdomain1.example.com"></iframe>
</div>
<div>
<iframe id="outer_iframe_2" src="https://subdomain2.example.com">
<div>
<iframe id="inner_iframe_2" src="https://subdomain4.example.com"></iframe>
</div>
</iframe>
</div>
<div>
<iframe id="outer_iframe_3" src="https://subdomain3.example.com"></iframe>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我打算inner_frame_2使用 Userscript获取和修改嵌套 iframe(例如)中的值,因此应该可以绕过同源策略。但是示例GM_xmlhttpRequest似乎依赖于 GET/POST 请求,而我只想处理这些 iframe 中已经加载的页面数据。
我是误解了GM_xmlhttpRequest,还是我应该在这里采取另一种方法?