Javascript 为什么';t.数据=”t;[filepath]“文件路径”;在Internet Explorer中工作?

Javascript 为什么';t.数据=”t;[filepath]“文件路径”;在Internet Explorer中工作?,javascript,html,internet-explorer,Javascript,Html,Internet Explorer,我有一个显示PDF文档的页面。此文档有多个版本可用。我有一个不同版本的下拉列表。用户可以选择他们想要的版本,选择后,页面上的PDF文档以及网页上的标题会发生变化,以反映文档版本。这是通过一些简单的JavaScript实现的 它目前在Chrome和Firefox中运行良好。但是,在Internet Explorer(版本11)中,显示的PDF不会更改。只有标题更改 我已经检查了控制台日志,没有错误。 我尝试过其他方法,例如: document.getElementById("pdfView").s

我有一个显示PDF文档的页面。此文档有多个版本可用。我有一个不同版本的下拉列表。用户可以选择他们想要的版本,选择后,页面上的PDF文档以及网页上的标题会发生变化,以反映文档版本。这是通过一些简单的JavaScript实现的

它目前在Chrome和Firefox中运行良好。但是,在Internet Explorer(版本11)中,显示的PDF不会更改。只有标题更改

我已经检查了控制台日志,没有错误。 我尝试过其他方法,例如:

document.getElementById("pdfView").setAttribute("data", "filepath.pdf");
但问题是一样的(我读到这在IE中无论如何都不起作用)。我一直在寻找一个替代方法,可以工作,因为它似乎是一个我使用的可能是不兼容的IE

/* Title of document */ 

<h1 id="docTitle">Document title (version 1)</h1>

我测试了你的代码并复制了这个问题。然后我尝试使用
而不是
,它可以在所有浏览器中正常工作。您可以更改代码的某些部分,如下所示:

/* The PDF viewer which displays the file. By default, latest version. */

<div id="pdfViewerStyle">
    <iframe src="filev2.pdf" width="800" height="600" id="pdfView"></iframe>
</div>
/* The PDF viewer which displays the file. By default, latest version. */

<div id="pdfViewerStyle">
    <object data="filev2.pdf" id="pdfView" type="application/pdf" 
     width="100%" height="100%">
    </object>
</div>
/*The JavaScript to allow H1 title and pdf filepath to change and dynamically update page depending on user's selection.*/

function selectDocument() {

    var index = document.getElementById("documentList").selectedIndex;

    // if the document selected is version 1
    if(index == 0) {
      //change the title
      document.getElementById("docTitle").innerHTML="Document title (version 1)";

      //change the pdf viewer filepath to the version 1 document
      document.getElementById("pdfView").data="filev1.pdf";
    }

    // if the document selected is version 2
    else if (index == 1) {
      //change the title
      document.getElementById("docTitle").innerHTML="Document title (version 2)";

      //change the pdf viewer filepath to the version 2 document
      document.getElementById("pdfView").data="filev2.pdf";
    }

}
/* The PDF viewer which displays the file. By default, latest version. */

<div id="pdfViewerStyle">
    <iframe src="filev2.pdf" width="800" height="600" id="pdfView"></iframe>
</div>
// if the document selected is version 1
document.getElementById("pdfView").src = "filev1.pdf";

// if the document selected is version 2
document.getElementById("pdfView").src = "filev2.pdf";