-1
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.

0

1 Answer 1

0

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>

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.