SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: Object tag

  1. #1
    Spam Can Kill!!! Disk-t's Avatar
    Join Date
    Jul 2001
    Location
    n/a
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Object tag

    How do I edit the src of an <object> tag using JS?

  2. #2
    SitePoint Member Ralf-J's Avatar
    Join Date
    Oct 2001
    Location
    Hannover, Germany
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •