drake035
drake035

Reputation: 2897

Replacing width and height in markup with a JS regular expression

I have two JS variables X and Y. In my markup there's a line starting with:

<iframe frameborder="0" width="600" height="337" ..

I want to replace the width's value by X's value and the height's value to Y's value. Could somebody help me with the regular expression to achieve this ?

Upvotes: 0

Views: 200

Answers (1)

Alnitak
Alnitak

Reputation: 339955

This is not a regexp problem.

Use DOM methods to find the <iframe> tag, and then just set its .width and .height properties.

For example, if there's only one <iframe> on the page:

var iframe = document.getElementsByTagName('iframe')[0];
iframe.width = x;
iframe.height = y;

It would be better to put an ID tag on the <iframe>, though:

var iframe = document.getElementById('myid');
... as above

If setting those properties doesn't work (it does on a Canvas, I haven't tried it on an iFrame) then set the CSS style properties instead.

Upvotes: 1

Related Questions