-
Object tag
How do I edit the src of an <object> tag using JS?
-
SitePoint Member
What you mean is not src ( which is part of the image ) but the path to the object, right?
<object data="myvideo.avi" type="video/x-msvideo" name="myobject">
<img src="file.ext">
</object>
If you want to change the path to the data it should work with:
window.document.myobject.data="mynewvideo.avi";
You also need a event to change the path. To test it you can copy this into the body :
<object data="myvideo.avi" type="video/x-msvideo" name="myobject" onMouseOver='changePath()'>
<img src="file.ext" width="9" height="9" border="0" alt="" ></object>
It's using the onMouseover event to call the function changePath().
Now insert the following script to the head of the page:
<script language='JavaScript1.2'>
<!--
function changePath()
{
alert(window.document.myobject.data);
window.document.myobject.data="mynewvideo.avi";
alert(window.document.myobject.data);
}
/-->
</script>
The alert window shows you the content of myobject.data before and after the path is changed - it's only to test the function.
I hope this helps.
regards
Ralf-J.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
Bookmarks