Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JQuery只在Firefox上工作_Jquery_Html - Fatal编程技术网

JQuery只在Firefox上工作

JQuery只在Firefox上工作,jquery,html,Jquery,Html,我正在为用户创建一个HTML首页,以查看我们的“如何”文档,PDF被添加到页面上,使用下面的JQuery创建预览。这在Firefox中运行良好,但在IE或Chrome中不起作用,非常感谢您的帮助,谢谢 $(document).ready(function() { "use strict"; $('.btn').click(function() { var idToSRC = './HTA_' + this.id + '.pdf';

我正在为用户创建一个HTML首页,以查看我们的“如何”文档,PDF被添加到页面上,使用下面的JQuery创建预览。这在Firefox中运行良好,但在IE或Chrome中不起作用,非常感谢您的帮助,谢谢

    $(document).ready(function() {
        "use strict";
        $('.btn').click(function() {
            var idToSRC = './HTA_' + this.id + '.pdf';
            $('#viewer').attr('src', idToSRC);
        });
    });

您可以使用JQuery clone()方法(我使用的URL是示例PDF):

更改Src
$(文档).ready(函数(){
“严格使用”;
$('.btn')。单击(函数(){
//var idToSRC='./HTA_'+this.id+'.pdf';
变量idToSRC=”http://www.reservoirminerals.com/files/doc_downloads/test.pdf";
var$viewerDiv=$('#viewer').parent();
var viewerClone=$('#viewer').clone().attr('src',idToSRC);
$viewerDiv.html(viewerClone);
}); });
看到它在这里工作:


可能是因为这些浏览器没有安装adobe插件?@techfoobar我以为Chrome现在有内置的PDF查看器。你检查控制台有没有错误吗?
#viewer
是iframe吗?如果您观看网络调试器,对PDF的请求是否会发生?如果调试代码,
$(“#查看器”)
是否真的与Chrome上的某些内容匹配?如果是这样,您可以将
src
更改为其他网站或其他内容吗?根据浏览器的不同,您通常无法动态更改嵌入标记的src。相反,您需要用一个新的嵌入标记替换它。看到这些线索:很高兴我能帮忙。别担心,接受就够了,谢谢。:)
<button type="button" class="btn">Change Src</button>
<div>
    <embed id="viewer" src="http://www.education.gov.yk.ca/pdf/pdf-test.pdf" width="500" height="680"></embed>
</div>

 $(document).ready(function() {
        "use strict";
        $('.btn').click(function() {
            //var idToSRC = './HTA_' + this.id + '.pdf';
            var idToSRC = "http://www.reservoirminerals.com/files/doc_downloads/test.pdf";
            var $viewerDiv = $('#viewer').parent();          
            var viewerClone = $('#viewer').clone().attr('src', idToSRC);
            $viewerDiv.html(viewerClone);
        }); });