我正在使用以下html在网页中嵌入PDF: -
<object id="pdf" classid="clsid:CA8A9780-280D-11CF-A24D-444553540000" width="1024" height="600">
<param name="SRC" value="/GetDoc.ashx?SOID=<%=Html.Encode(Model.OrderID)%>" />
<embed src="/GetDoc.ashx?SOID=<%=Html.Encode(Model.OrderID)%>" width="1024" height="600">
<noembed> Your browser does not support embedded PDF files. </noembed>
</embed>
</object>
Run Code Online (Sandbox Code Playgroud)
PDF的加载速度有点慢,所以我想隐藏对象并显示加载消息/ gif,直到它完全加载,因此用户不会看空白屏幕.
我真正需要的是一种告诉对象何时满载的方法.我已经尝试了'onload'事件,但它似乎永远不会被解雇.
我开始认为这可能是不可能的,但要问......
小智 13
我不知道为什么每个人都这么努力.
<object data="yourfile.pdf" style="background: transparent url(AnimatedLoading.gif) no-repeat center;" type="application/pdf" />
Run Code Online (Sandbox Code Playgroud)
use*_*118 10
以下代码有效.
<div style="background: transparent url(loading.gif) no-repeat">
<object height="1250px" width="100%" type="application/pdf" data="aaa.pdf">
<param value="aaa.pdf" name="src"/>
<param value="transparent" name="wmode"/>
</object>
</div>
Run Code Online (Sandbox Code Playgroud)
我正在使用jQuery ajax将PDF加载到浏览器缓存中.然后我用浏览器缓存中的数据创建嵌入元素.
var url = "http://example.com/my.pdf";
// show spinner
$.mobile.showPageLoadingMsg('b', note, false);
$.ajax({
url: url,
cache: true,
mimeType: 'application/pdf',
success: function () {
// display cached data
$(scroller).append('<embed type="application/pdf" src="' + url + '" />');
// hide spinner
$.mobile.hidePageLoadingMsg();
}
});
Run Code Online (Sandbox Code Playgroud)
您还必须正确设置http标头.
HttpContext.Response.Expires = 1;
HttpContext.Response.Cache.SetNoServerCaching();
HttpContext.Response.Cache.SetAllowResponseInBrowserHistory(false);
HttpContext.Response.CacheControl = "Private";
Run Code Online (Sandbox Code Playgroud)
“当对象正在加载但尚未完成时,会显示标签内的内容。”
所以把你的旋转器放在那里,它应该会很适合你。而且您无需编写任何 JavaScript。
源代码: http: //en.wikibooks.org/wiki/XHTML/XHTML_Objects