【发布时间】:2021-11-24 01:26:14
【问题描述】:
假设我们在 iFrame 中有这段代码。我很确定 iFrame 来自同一个域,我认为这很重要。
<div id="10">You become 1 best coder</div>
我想要一个 Greasemonkey 脚本,它仅在“div id=10”和文本(或部分文本)都为真时运行脚本。
我试过了:
// ==UserScript==
// @name Script
// @include https://www.somesite.com/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js
// @grant GM_addStyle
// ==/UserScript==
/*- The @grant directive is needed to work around a design change
introduced in GM 1.0. It restores the sandbox.
*/
var intv = setInterval(function() {
const sp = document.querySelector('#10'); // find id (some)
if (sp && sp.textContent === 'You become 1 best coder') {
alert('Hello world!');
}
}, 5000);
这适用于具有常规内容的常规页面。但是,当我需要脚本识别以便在 iFrame 中运行加载的内容时,脚本不会运行。
以下是 iFrame 代码示例:
<iframe src="something.php?text=M0000310y100g190e500A78014607601&lalala=tT6&ctrl=032a4c3342e76e97ea21821a5c5f800e&mamama=c2ed5535532cc20aef064db2b4" width="100%" height="100%" frameborder="0"></iframe>
我假设 iFrame 来自同一个域,因为如果它来自不同的域,我认为 src="" 会有所不同...
有人可以帮忙吗?谢谢
【问题讨论】:
标签: javascript iframe greasemonkey