Create a javascript file to have <object> or <embed> tags in it for use in various html pages - Stac

I have more than 200 pages with the same <object> or <embed> tags for.I need to have a .j

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
Add a ment  | 

1 Answer 1

Reset to default 4

Firstly, 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条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信