本文介绍了注入DOM时如何防止iframe加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在注入DOM时阻止iframe加载?
例如,此代码创建一个带有src的iframe,开始下载。
f = B.Node.create('< iframe class =offscreenrole =presentationtabindex = - 1id = '+ d +'src ='+ Z + Y +'>');
F(body)。appendChild(f);
没有任何图书馆,阻止iframe加载或停止下载的方法是什么? p>
防止iframe注入也是可以接受的。
是否修改appendChild() ?
我正在使用Opera 11.50 Build 1074。
解决方案
// == UserScript ==
// @name增强雅虎邮件
// @author XP1(https://github.com/XP1/)
// @namespace https://gist.github.com/1126767/
// @version 1.0
// @description在Yahoo!邮件,在新窗口中打开下载iframe,以便如果文件类型与Opera浏览器相关联,则可以打开附件。
// @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 .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));
How to prevent iframe from loading when injected into the DOM?
For example, this code creates an iframe with a src that begins a download.
f = B.Node.create('<iframe class="offscreen" role="presentation" tabindex="-1" id="' + d + '" src="' + Z + Y + '">');
F("body").appendChild(f);
Without any libraries, what are ways to prevent the iframe from loading or to stop the download?
Preventing the iframe injection is also acceptable.
Is it a good idea to modify the behavior of "appendChild()"?
I'm using Opera 11.50 Build 1074.
解决方案
https://gist.github.com/1126767/
// ==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));
这篇关于注入DOM时如何防止iframe加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!