I have more than 200 pages with the same <object>
or <embed>
tags for. I need to have a .js file to have this repeatative information in it. This is the tag is repeating in all 200-300 page:
<OBJECT width="720" height="540">
<PARAM NAME="Src" value="../pdf/sign-va.pdf">
<embed width="720" height="540" src="../pdf/sign-va.pdf"
href="../pdf/sign-va.pdf"></embed></OBJECT>
I have more than 200 pages with the same <object>
or <embed>
tags for. I need to have a .js file to have this repeatative information in it. This is the tag is repeating in all 200-300 page:
<OBJECT width="720" height="540">
<PARAM NAME="Src" value="../pdf/sign-va.pdf">
<embed width="720" height="540" src="../pdf/sign-va.pdf"
href="../pdf/sign-va.pdf"></embed></OBJECT>
Share
Improve this question
edited Jun 29, 2010 at 0:43
Jamie Wong
18.4k8 gold badges66 silver badges81 bronze badges
asked Jun 29, 2010 at 0:25
JayJay
211 silver badge2 bronze badges
2
- Why do you want this in JavaScript? I'd rather put these elements in your document use a server-side script. – Marcel Korpel Commented Jun 29, 2010 at 0:48
- You might want to consider using server side includes if your server offers them. You could even write a program to modify all your pages. See en.wikipedia/wiki/Server_Side_Includes to get started with server side includes. – DaveB Commented Jun 29, 2010 at 0:59
1 Answer
Reset to default 4Firstly, Marcel Korpel is right: using a server-side technology to include this snippet is the smarter way to go. If that isn't an option for you for whatever reason, you can do this:
To insert it using Javascript, you'd firstly need some way to identify where to put it. You could do this by having a div with a certain ID, or always put it in the same place (e.g.: at the end of the <body>
).
var filename = '../pdf/sign-va.pdf',
w = 720,
h = 540
;
var obj = document.createElement('object');
obj.setAttribute('width', w);
obj.setAttribute('height', h);
var param = document.createElement('param');
param.setAttribute('name', 'Src');
param.setAttribute('value', filename);
obj.appendChild(param);
var embed = document.createElement('embed');
embed.setAttribute('width', w);
embed.setAttribute('height', h);
embed.setAttribute('src', filename);
embed.setAttribute('href', filename);
obj.appendChild(embed);
// here is where you need to know where you're inserting it
// at the end of the body
document.body.appendChild(obj);
// OR, into a particular div
document.getElementById('some_id').appendChild(obj);
If you were using something like jQuery, this bees much less verbose:
$('<object></object>', { width: w, height: h})
.append($('<param />', { name: 'src', value : filename }))
.append($('<embed></embed>', {
width: w, height: h,
src : filename, href : filename
}))
.appendTo(document.body)
;
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744705065a4589009.html
评论列表(0条)