/    Sign up×
Community /Pin to ProfileBookmark

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>[/CODE]

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!

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@David_HarrisonMay 27.2004 — 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.
Copy linkTweet thisAlerts:
@duboisdauthorMay 28.2004 — 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!
Copy linkTweet thisAlerts:
@FangMay 28.2004 — You can not change the object's data without reloading the page.
Copy linkTweet thisAlerts:
@duboisdauthorMay 28.2004 — 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?
Copy linkTweet thisAlerts:
@FangMay 28.2004 — 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:
function ChangeIt() {
var aO=document.getElementsByTagName('object');
for(var i=0; i&lt;aO.length; i++) {
if(aO[i].getAttribute('name')=="main") {
aO[i].setAttribute('data', 'another.htm');
}
}
}

You can change the height by changing [I]setAttribute[/I]
Copy linkTweet thisAlerts:
@David_HarrisonMay 28.2004 — [i]Originally posted by duboisd [/i]

[B]The name attribute is NOT deprecated!

The w3schools website says it is valid in Strict, Transitional and Frameset![/B]
[/QUOTE]
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?
×

Success!

Help @duboisd spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.27,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...