I want to change the src attribute of an embed object. I have:
<embed class="flash "id="flash" src="swf/pano.swf?panoSrc=images/a.jpg"
allowFullScreen="true"
width="1280" height="640" quality="high"
pluginspage="http://www.macromedia.com/go/getflashplayer"
type="application/x-shockwave-flash" bgcolor="#DDDDDD"/>
and I’ve tried
function change()
{
document.getElementById("flash").setAttribute('src', 'swf/pano.swf?panoSrc=b.jpg');
}
but it didn’t work in Chrome, “only” in Firefox, IE and Opera. How can I fix it (to make it work in Chrome)? Did I do anything wrong?
EDIT: here is the whole HTML file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title></title>
<script>
function change() {
document.getElementById("flash").setAttribute('src', 'swf/pano.swf?panoSrc=a.jpg');
}
</script>
</head>
<body>
<embed class="flash" id="flash" src="swf/pano.swf?panoSrc=images/sau.jpg" allowFullScreen="true"
width="1280" height="640" quality="high"
pluginspage="http://www.macromedia.com/go/getflashplayer"
type="application/x-shockwave-flash" bgcolor="#DDDDDD"/>
<script>
change();
</script>
</body>
Link to the page: http://chin.comli.com/test.html
Move your script call to be AFTER the code it’s intended to affect, or put it in a window.onload call. As you have it it’s trying to execute on an element before it exists.Long story short, based on Changing object embed source via jquery, Dynamically change embedded video src in IE/Chrome (works in Firefox), JavaScript: Changing src-attribute of a embed-tag, and http://code.google.com/p/chromium/issues/detail?id=69648, it looks like this is a bug in Chrome and the only workaround is to remove the entire
<embed>element, and then re-insert it with the changed src.