changing the data attribute of <object>

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • chotiwallah

    #1

    changing the data attribute of <object>

    this is the html:

    <a href="Javascrip t:change();">ch ange</a>

    <object data="a.htm" type="text/html" width="200" height="200"
    id="obj"></object>



    and this the javascript:

    function change()
    {
    document.getEle mentById('obj') .setAttribute(' data','b.htm');

    alert(document. getElementById( 'obj').data);
    }

    this little script shall change the data of the <object> from 'a.htm'
    to 'b.htm' - which it actually does. the alert() shows 'b.htm' as
    data.

    but: 'b.htm' is not displayed, the content of object doesn't change -
    same in firefox, ns, ie.

    what am i missing?

    any help appreciated, micha
  • Martin Honnen

    #2
    Re: changing the data attribute of &lt;object&g t;



    chotiwallah wrote:
    [color=blue]
    > this is the html:
    >
    > <a href="Javascrip t:change();">ch ange</a>
    >
    > <object data="a.htm" type="text/html" width="200" height="200"
    > id="obj"></object>
    >
    >
    >
    > and this the javascript:
    >
    > function change()
    > {
    > document.getEle mentById('obj') .setAttribute(' data','b.htm');
    >
    > alert(document. getElementById( 'obj').data);
    > }
    >
    > this little script shall change the data of the <object> from 'a.htm'
    > to 'b.htm' - which it actually does. the alert() shows 'b.htm' as
    > data.
    >
    > but: 'b.htm' is not displayed, the content of object doesn't change -
    > same in firefox, ns, ie.
    >
    > what am i missing?[/color]

    That works only in Opera I think, in general it is easier to use an iframe
    <iframe name="iframeNam e" src="a.htm"></iframe>
    and then a link
    <a href="b.htm" target="iframeN ame">change</a>
    as iframes work much better in current browsers than objects and as that
    way you do not need any script to load the new page, a normal link works.
    I know that the <iframe> element is not in HTML 4.01 strict but the
    <object> implementation in browsers is bad and inconsistent enough to
    use <iframe> with the transitional HTML 4.01 DTD. Even if you insist on
    using script to load the new page you will find that
    window.frames.i frameName.locat ion.href = 'b.html';
    works consistently in browsers from Opera 6, Netscape 6, IE 4 on while
    you have found that scripting object is a pain.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/

    Comment

    Working...