7

第一次加载我的 jQuery 移动支持页面时,我无法让 iFrame 显示。

我有一个 iFrame,如下所示:

<iframe id="manual" src="pdf/manual.pdf" style="width: 100%; height: 100%;"></iframe>

并且由于某种原因,当页面加载时,iFrame 无法加载它。如果我刷新页面,我只能看到 PDF 文件。这是为什么?

为什么在没有页面刷新的情况下,PDF 文件首先没有显示在 iFrame 中?

感谢大家的任何见解。

编辑:

当我尝试使用 safari 打开页面时,我收到以下警告:

Resource interpreted as Document but transferred with MIME type application/pdf.

这可能与为什么 PDF 无法正确加载有关吗?

4

2 回答 2

3

因为它是一个 ajax 调用,所以 iframe 必须以不同的方式编码。检查这个网站,有一些解决方案... 网站

对网站中的代码稍作修改以打开 pdf。

Page1.html

<!DOCTYPE html> 
<html> 
    <head> 
    <title>Demo Page</title> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css" />
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
    <script type="text/javascript" src="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js"></script>
    <script type="text/javascript" src="js/main.js"></script>
</head> 
<body> 
<div data-role="page">
    <div data-role="header">
        <h1>Demo Page</h1>
    </div><!-- /header -->
    <div data-role="content">   
        <!-- this is a regular page call-->
        <a href="page2.html" data-role="button">Another Page</a>
        <!-- the functionality for this page is defined in "javascript.js" -->
        <!-- we put it in a data attribute to avoid spiders spidering the link and hammering the device -->
        <a href="#" id="perform-function" data-role="button" data-link="FocusFree.pdf">Perform Function</a>
    </div><!-- /content -->
</div><!-- /page -->
</body>
</html>

Page2.html

<!DOCTYPE html> 
<html> 
    <head> 
    <title>Another Page</title> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css" />
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
    <script type="text/javascript" src="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js"></script>
</head> 
<body> 
<div data-role="page" data-add-back-btn="true">
    <div data-role="header">
        <h1>Another Page</h1>
    </div><!-- /header -->
    <div data-role="content">   
        <p>This is another page, dude.</p>
    </div><!-- /content -->
</div><!-- /page -->
</body>
</html>

main.js

$(document).ready(function(){

    $('#perform-function').bind('click', function(){
        // we're storing the link in an attribute
        // called 'data-link':
        var url = $(this).attr('data-link');        
        // create iframe if not there, comment display none to see it
        if ($('#temp-iframe').length === 0) {
            $('<iframe />').attr({
                id: 'temp-iframe',
                name: 'temp-iframe',
                height: '100%',
                width: '100%'
            }).css({                
                position: 'absolute',
                left: '50%',
                bottom: 0
            }).bind('load', function(){             
            }).appendTo('body');
        }
        // call the url into the iframe
        $('#temp-iframe').attr('src', url);
        // jquerymobile already does this because the link is just "#"
        // but if you end up 
        return false; 
    });

});
于 2012-05-21T10:17:46.110 回答
3

我只是尝试使用 rel="external" 它无需刷新即可工作。第一个链接是 ajax 调用,第二个链接不是。这是直截了当的,不确定我是否错过了你拥有的其他东西..

Page1.html

<!DOCTYPE html> 
<html> 
    <head> 
    <title>Demo Page</title> 
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css" />
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
    <script type="text/javascript" src="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js"></script>
</head> 
<body> 
<div data-role="page">
    <div data-role="header">
        <h1>Demo Page</h1>
    </div>
    <div data-role="content">           
        <a href="page2.html" data-role="button">Another Page</a>
        <a href="page2.html" rel="external" data-role="button">View User Manual</a>         
    </div>
</div>
</body>
</html>

Page2.html

<!DOCTYPE html> 
<html> 
    <head> 
    <title>Another Page</title>     
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css" />
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
    <script type="text/javascript" src="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js"></script>
</head> 
<body>

<div data-role="page" data-add-back-btn="true">
    <iframe id="manual" src="FocusFree.pdf" style="width: 100%; height: 100%;"></iframe> 
    <div data-role="header" data-theme="none">
        <h1>Another Page</h1>
    </div>
    <div data-role="content" data-theme="none"> 
        <p>This is another page, dude.</p>
    </div>
</div>

</body>
</html>
于 2012-05-22T06:16:43.863 回答