www.webdeveloper.com
Results 1 to 7 of 7

Thread: changing source data of an <object>

  1. #1
    Join Date
    May 2004
    Location
    Aalst, Belgium
    Posts
    3

    changing source data of an <object>

    I'm using XHTML, strict DTD

    this code is in my page:

    Code:
    <object width="751" height="372" name="main" data="main.htm"></object>
    Can I change the data of this object via JavaScript? For example by clicking on a link?
    At the moment "main.htm" is shown in the object. I would like to show "page1.htm" in the object by clicking on a link in the page.

    When I am in the object, I can manage this with window.document.location, but when I'm working OUTSIDE the object I'm kinda stuck...
    I would appreciate any help.

    Please do not propose to use an iframe, because I have to use the <object>.
    Thanks for any help in advance!

  2. #2
    Join Date
    Dec 2002
    Location
    Manchester, UK
    Posts
    6,275
    If you want to display a page inside another page then you should be using an iframe. Besides that you are using the name attribute which is depreciated, so to be valid you should also be using a transitional DTD.
    Every fight is a food fight when you’re a cannibal.

  3. #3
    Join Date
    May 2004
    Location
    Aalst, Belgium
    Posts
    3
    The name attribute is NOT deprecated!
    The w3schools website says it is valid in Strict, Transitional and Frameset!
    And if you can change the source page in the <object> from within, you can also do this from outside, I'm just looking for the code.

    Besides, an iframe doesn't work in all browsers, an object does!

  4. #4
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    You can not change the object's data without reloading the page.

  5. #5
    Join Date
    May 2004
    Location
    Aalst, Belgium
    Posts
    3
    you mean without reloading the whole page? Or just the one that's inside the object?
    When I do document.location=... from the page within the object, it works.
    If this works, there has to be some code to do this from the page where the object is in?

  6. #6
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    You have to reload the whole page that contains the object.
    You can change it's width and height, but not the contents of the object.
    Try using this code:
    Code:
    function ChangeIt() {
    var aO=document.getElementsByTagName('object');
    for(var i=0; i<aO.length; i++) {
    	if(aO[i].getAttribute('name')=="main") {
        	aO[i].setAttribute('data', 'another.htm');
            }
    	}
    }
    You can change the height by changing setAttribute

  7. #7
    Join Date
    Dec 2002
    Location
    Manchester, UK
    Posts
    6,275
    Originally posted by duboisd
    The name attribute is NOT deprecated!
    The w3schools website says it is valid in Strict, Transitional and Frameset!
    Terribly sorry, I was under the impression that the name attribute was depreciated for all but form elements. Does it validate with the W3C validator?
    Every fight is a food fight when you’re a cannibal.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles