最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - Viewer.JS File Name from Title Attribute - Stack Overflow

matteradmin7PV0评论

I'm using viewer.js (/) to view pdf's on a website, and I want to pull the attribute "title" from the iframe code to title the document.

At the moment the code is as follows

<iframe id="viewer" src = "/ViewerJS/#../demo/ohm2013.odp" width='400' height='300' allowfullscreen webkitallowfullscreen></iframe>

and I want to be able to do this

<iframe id="viewer" src = "/ViewerJS/#../demo/ohm2013.odp" width='400' height='300' allowfullscreen webkitallowfullscreen title="Document Title"></iframe>

I know the bit of code in the js file I need to edit is as follows

document.getElementById("documentName").innerHTML=document.title

and I tried the following but with no luck

document.getElementById("documentName").innerHTML=document.attr('title')

I'm just not sure how to get the attribute.

The full source code for viewer.js can be viewed at .js

I'm using viewer.js (http://viewerjs/) to view pdf's on a website, and I want to pull the attribute "title" from the iframe code to title the document.

At the moment the code is as follows

<iframe id="viewer" src = "/ViewerJS/#../demo/ohm2013.odp" width='400' height='300' allowfullscreen webkitallowfullscreen></iframe>

and I want to be able to do this

<iframe id="viewer" src = "/ViewerJS/#../demo/ohm2013.odp" width='400' height='300' allowfullscreen webkitallowfullscreen title="Document Title"></iframe>

I know the bit of code in the js file I need to edit is as follows

document.getElementById("documentName").innerHTML=document.title

and I tried the following but with no luck

document.getElementById("documentName").innerHTML=document.attr('title')

I'm just not sure how to get the attribute.

The full source code for viewer.js can be viewed at http://viewerjs/ViewerJS/viewer.js

Share Improve this question edited Jun 25, 2014 at 9:51 dpDesignz asked Jun 25, 2014 at 9:15 dpDesignzdpDesignz 1,95910 gold badges35 silver badges72 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7

It is possible to pass the title parameter like this:

<iframe src="/ViewerJS/?title=My PDF Title#../demo/ohm2013.odp"></iframe>

Just notice that it must be placed before the document's URL.

Worked out how to do it, it just needed to be as follows

document.getElementById("documentName").innerHTML=window.frameElement.title

Post a comment

comment list (0)

  1. No comments so far