Javascript 如何防止在注入DOM时加载iframe?
如何防止在注入DOM时加载iframe 例如,这段代码创建了一个带有src的iframe,开始下载Javascript 如何防止在注入DOM时加载iframe?,javascript,dom,iframe,frame,code-injection,Javascript,Dom,Iframe,Frame,Code Injection,如何防止在注入DOM时加载iframe 例如,这段代码创建了一个带有src的iframe,开始下载 f = B.Node.create('<iframe class="offscreen" role="presentation" tabindex="-1" id="' + d + '" src="' + Z + Y + '">'); F("body").appendChild(f); f=B.Node.create(“”); F(“身体”)。附属于儿童(F); 如果没有任何库,有
f = B.Node.create('<iframe class="offscreen" role="presentation" tabindex="-1" id="' + d + '" src="' + Z + Y + '">');
F("body").appendChild(f);
f=B.Node.create(“”);
F(“身体”)。附属于儿童(F);
如果没有任何库,有什么方法可以阻止iframe加载或停止下载
防止iframe注入也是可以接受的
修改“appendChild()”的行为是个好主意吗
我使用的是Opera 11.50 Build 1074。您不能在所有(如果有的话)浏览器中覆盖像
appendChild这样的函数。防止iFrame被注入的唯一方法是不包括任何执行任意DOM注入的JavaScript库
如果您想阻止自己的代码插入iframe,只需添加一些HTML“消毒”功能。附加空iframe
document.body.appendChild(document.createElement('iframe').setAttribute('id', 'myiFrame'));
当您要加载内容时:
document.getElementById('myiFrame').setAttribute('src', 'http://blah.com/blah.htm');
如果你不想让IFrame有内容,为什么要注入IFrame?@GolezTrol,我不是在注入IFrame。其他人是。我无法控制雅虎!雅虎上的邮件JavaScripts服务器。雅虎!Mail正在注入iframe。您可以控制在文档中加载该脚本,还是第三方内容正在加载脚本?@Jacob,我可以在客户端控制脚本。我已经做了一个用户JS的工作。请看我的答案。这就是我正在做的,当我在没有src
的情况下创建它时,iframe会加载一个空和一个空。也许过去它是有用的。。。
// ==UserScript==
// @name Enhance Yahoo! Mail
// @author XP1 (https://github.com/XP1/)
// @namespace https://gist.github.com/1126767/
// @version 1.0
// @description In Yahoo! Mail, opens the download iframe in a new window so that the attachment can be opened if the file type is associated with the Opera browser.
// @include http*://mail.yahoo.*/*
// @include http*://*.mail.yahoo.*/*
// @include http*://mail.yimg.*/*
// @include http*://*.mail.yimg.*/*
// @include http*://yahooapis.*/*
// @include http*://*.yahooapis.*/*
// ==/UserScript==
/*jslint browser: true, vars: true, white: true, maxerr: 50, indent: 4 */
(function (topWindow)
{
"use strict";
if (window.self === topWindow)
{
var disableDownloadIframe = function ()
{
topWindow.addEventListener("DOMNodeInserted", function (event)
{
var sourceElement = event.srcElement;
if (sourceElement.tagName.toLowerCase() === "iframe" && sourceElement.hasAttribute("id") && sourceElement.getAttribute("id").indexOf("#dlFrame") !== -1)
{
var downloadLink = sourceElement.getAttribute("src");
sourceElement.parentNode.removeChild(sourceElement);
window.open(downloadLink);
}
}, false);
};
disableDownloadIframe.call(this);
}
}(window.top));