I have a page that displays a PDF document. There are multiple versions of this document available. I have a dropdown list of the different versions. The user can select the version they want and upon selection, the PDF document on the page changes, as well as the title on the web page to reflect the document version. This is done through some simple JavaScript.
It currently works fine in Chrome and Firefox. However in Internet Explorer (Version 11), the PDF displayed does not change. Only the H1 title changes.
I've checked the console log and there are no errors. I've tried alternate methods, such as:
document.getElementById("pdfView").setAttribute("data", "filepath.pdf");
but the issue is the same (and I read that this doesn't work in IE anyway). I have been looking for an alternate method that could work as it appears the one I'm using probably isn't compatible in IE.
/* Title of document */
<h1 id="docTitle">Document title (version 1)</h1>
/* The dropdown list to select a document version */
<select id="documentList" onchange="selectDocument()">
<option value="v1">Document v1</option>
<option value="v2">Document v2</option>
</select>
/* 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";
}
}