Html 如何向来自标记的简单请求添加加载掩码

Html 如何向来自标记的简单请求添加加载掩码,html,Html,我通过以下操作从服务器请求PDF: html: '<embed type="application/pdf" width="1500px" height="800px" src="' + src + '"/>' 现在我知道在AJAX请求中添加加载掩码非常容易,但是如何将其添加到上述请求中呢。假设我这样做: Ext.loadMask(); html: '<embed type="application/pdf" width="1500px" height="800px" src

我通过以下操作从服务器请求PDF:

html: '<embed type="application/pdf" width="1500px" height="800px" src="' + src + '"/>'
现在我知道在AJAX请求中添加加载掩码非常容易,但是如何将其添加到上述请求中呢。假设我这样做:

Ext.loadMask();
html: '<embed type="application/pdf" width="1500px" height="800px" src="' + src + '"/>'
Ext.hideMask();
甚至在服务器返回响应之前,hideMask也会被调用


我试过像这样的onload:

html: '<embed type="application/pdf" width="1500px" height="800px" src="' + src + '" onload=' + console.log("this PDf has been loaded") + '/>' 

但是,即使在我看到PDF之前,它也会被调用,因为您的请求,您在提供的代码中已经执行了异步代码

您可以做的是尝试实现一个可能有效的高风险事件侦听器,但这是一个在不同浏览器之间存在争议的主题

比如:

var targetEl = document.getElementByID("target");
targetEl.innerHTML = '<embed id="embeded" type="application/pdf" width="1500px" height="800px" src="' + src + '"/>';
embeded = document.getElementByID("embeded");
embeded.addEventListener("load", function() { Ext.hideMask(); });
但是你肯定不能确定这是否适用于所有浏览器。更好的选择是使用$embed.on'load',函数{…};-jQuery库

参考资料:


我也尝试过像这样的onload:html:但即使在我看到pdf之前就调用了它,因此很难控制嵌入的标记和iframe中发生了什么。这就是为什么服务提供者提供他们自己的API来向父DOM元素返回一些信息。你可以阅读更多关于将PDF嵌入网站的内容。