28

我正在使用以下 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>

PDF的加载速度可能有点慢,所以我想隐藏对象并显示加载消息/ gif,直到它完全加载,这样用户就不会看到空白屏幕。

我真正需要的只是一种告诉对象何时完全加载的方法。我已经尝试过 'onload' 事件,但它似乎从未被解雇。

我开始认为这可能是不可能的,但问它永远不会伤害......

4

8 回答 8

14

我不知道为什么每个人都那么难。

<object data="yourfile.pdf" style="background: transparent url(AnimatedLoading.gif) no-repeat center;" type="application/pdf" />
于 2011-12-31T14:46:43.400 回答
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>
于 2010-01-22T23:46:09.930 回答
7

我正在将带有 jQ​​uery 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();
    }
});

您还必须正确设置 http 标头。


HttpContext.Response.Expires = 1;
HttpContext.Response.Cache.SetNoServerCaching();
HttpContext.Response.Cache.SetAllowResponseInBrowserHistory(false);
HttpContext.Response.CacheControl = "Private";
于 2012-08-16T14:26:22.480 回答
3

没有任何建议是有效的,因为 DOM 是在加载 PDF 内容之前加载的。所以 DOM 无法控制 ActiveX 内容

于 2009-11-09T11:49:45.537 回答
0

“在加载对象但尚未完成时显示标签内的内容。”

所以把你的微调器放在那里,它应该很适合你。而且您不必编写任何 JavaScript。

来源:http ://en.wikibooks.org/wiki/XHTML/XHTML_Objects

于 2009-07-16T15:07:36.070 回答
0

你会想要像 jQuery 的document.ready()函数这样的东西。对于非 IE 浏览器,您可以为 event 注册一个处理程序DOMContentLoaded,并且在加载所有图像和对象后调用您的处理程序函数。对于 IE,您必须不断检查该document.readyState属性,并等待它成为"complete".

如果您使用 jQuery,他们已经为您完成了艰苦的工作,所以您所要做的就是:

$(document).ready(function() {
    //take away the "loading" message here
});

如果您不想使用 jquery,则必须执行以下操作:

addEventListener('DOMContentLoaded', function() { 
    //take away the "loading" message here
});

function waitForIE() {

    if (!document.all) return;

    if (document.readyState == "complete") {
        //take away the "loading" message here
    }
    else {
        setTimeout(waitForIE, 10);
    }
}

waitForIE();
于 2009-07-16T15:13:45.200 回答
0
$(document).ready(function() {
   });

不起作用,因为这主要是 ondocument.readyState == interactive而不是 on document.readyState == complete

如果你用这个检查(document.readyState == "complete")设置一个计时器,它肯定会工作!

于 2012-08-13T17:40:23.187 回答
0
<embed onload='alert("I should be called")'></embed>
于 2015-10-28T04:56:33.660 回答