var filename2 = "PDFxx.pdf";
<object data=filename2 width="800" height="500"></object>
in JavaScript, I like to assign a var filename2, equals to "PDFxx.pdf" etc.
data=filename2 never works, but data="PDFxx.pdf" works fine.
Wondering how to accomplish that. Please advise.
Thanks in advance.
>Solution :
Create the <object> via JavaScript and inject it into your document
const filename2 =
"https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"; // "PDFxx.pdf";
const obj = Object.assign(document.createElement("OBJECT"), {
data: filename2,
width: 800,
height: 500,
});
document.body.append(obj);
object { border: 1px dotted; }
Alternately, query the element and set its data property
const filename2 =
"https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"; // "PDFxx.pdf";
document.querySelector("object").data = filename2;
object { border: 1px dotted; }
<object width="800" height="500"></object>