我想实现 JavaScript 来修改输入字段的内容iframe
从另一个域加载(这是网站 http://www.ah.nl/over-ah/services/mobiel/online-opwaarderen).
困难:
- 不知何故,jQuery 加载有延迟,所以我不得不使用
setTimeout()
以确保 jQuery 可用。
- 唯一的
iframe
从另一个域加载,导致Permission denied to access property 'document'
当我尝试使用时iframe.contentWindow.document
from 这个帖子 https://stackoverflow.com/questions/14451358/how-to-pick-element-inside-iframe-using-document-getelementbyid.
- 我尝试应用中提供的跨域技术这个帖子 https://stackoverflow.com/questions/28309576/access-an-element-inside-a-dynamically-created-cross-domain-iframe,但它不起作用。
- 元素的 ID 包含分号,因此应该使用来自这个帖子 https://stackoverflow.com/questions/5552462/handling-colon-in-element-id-with-jquery.
Script:
// ==UserScript==
// @name ah.nl
// @include http://www.ah.nl/over-ah/services/mobiel/*
// @include https://ezpay.liquix.eu/WebReloadSolution/*
// @grant none
// @namespace http://www.example.com/gmscripts/
// ==/UserScript==
document.domain= 'ah.nl';
if (self === top) {
setTimeout(function() {
try {
$('iframe').load(function() {
console.log("Start " + this.src);
var inputs = $('input', this.contentDocument);
console.log("Got " + inputs.length);
// Below does not work:
//inputs.find('#orderForm\\:msisdnConfirm, #orderForm\\:msisdn').val('1234567890');
});
} catch(e) {
console.log(e);
}
}, 1000);
}
生产:
Start https://ezpay.liquix.eu/WebReloadSolution/index.jsp?merchant=ahnl&language=nl&mode=reload&productCode=1
Got 1
之所以只有一个元素是因为<input>
元素位于顶部文档中。
谁能提供一个可行的 Greasemonkey 解决方案?
FF 43.0.1,油猴 v3.8。
None
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)