[英]MutationObserver on iFrame javascript
我有一個包含源www.abc/main.html
的 iframe
<iframe id="my-iframe" src="http://www.abc/main.html"></iframe>
abc/main.html 導入並執行一些 js 文件。 我想使用 MutationObserver 來獲取它正在導入的 js 文件的名稱。
var observer = new MutationObserver(function (mutations) {
mutations.forEach(function (mutation) {
[].filter.call(mutation.addedNodes, function (node) {
return node.nodeName == 'IFRAME';
}).forEach(function (node) {
node.addEventListener('load', function (e) {
console.log('loaded', node.src);
});
});
});
});
observer.observe(document.body, { childList: true, subtree: true });
這就是我正在使用的。 參考: SO 答案
但是我無法獲取 js 文件的名稱。 它與 iframe 源上的 CSP 設置有關嗎?
注意:iframe 內容與父文檔的來源不同。
MutationObserver 只觀察你自己的文檔。
如果沒有來自遠程站點的明確 CORS 支持,完全不可能觀察來自不同來源的幀或與之交互。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.