Javascript Reference - HTML DOM Embed width Property








The width attribute specifies the width of the embedded content in pixels.

The width property sets or gets the width attribute in an <embed> element.

Browser Support

Embed width Yes Yes Yes Yes Yes

Syntax

Return the width property.

var v = embedObject.width

Set the width property.

embedObject.width=pixels




Property Values

Value Description
pixels Set Specifies the width of the embedded content in pixels

Return Value

A Number type value representing the width of the embedded content in pixels.

Example

The following code shows how to change the width of an embedded file to 100 pixels.

<!DOCTYPE html>
<html>
<body>
<embed id="myEmbed" src="notExist.swf" width="200" height="200" style="border:1px solid">
<button onclick="myFunction()">test</button>
<script>
function myFunction() {
    document.getElementById("myEmbed").width = "100";
}
</script>
</body>
</html>




Example 2

The following code shows how to get the width of an embedded file.

<!DOCTYPE html>
<html>
<body>
<embed id="myEmbed" src="notExist.swf" width="200" height="200" style="border:1px solid">
<p id="demo"></p>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {
    var x = document.getElementById("myEmbed").width;
    document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>