/    Sign up×
Community /Pin to ProfileBookmark

JavaScript, HTML Frames

I’ve made a page split into 2 frames. (so, I have ‘[COLOR=”Red”][B]index.html[/B][/COLOR]‘ with descriptions about frames and which is the main frame-container, then I have ‘[B][COLOR=”red”]leftFrame.html[/COLOR][/B]‘, which contains my navigation, and ‘[B][COLOR=”Red”]mainFrame.html[/COLOR][/B]‘ which contains the main body of topic)

e.g. my [COLOR=”red”][B]leftFrame.html[/B][/COLOR] has the following source;

[CODE]
<html>
<head>
<title>Navigation</title>
</head>

<body>
<img id=”imgl” src=”imgs/0.png” alt=”” />
</body>
</html>
[/CODE]

then my mainFrame.html has the source, as follows;

[CODE]
<html>
<head>
<title>Main</title>
</head>

<body [COLOR=”red”][B]onload=”javascript:document.getElementById(‘imgl’).src = ‘imgs/1.png’;”[/B][/COLOR]>

[html content]

</body>
</html>
[/CODE]

How to reach an element of a “neighbour”-frame???

What must I type instead of

[CODE][COLOR=”red”][B]onload=”javascript:document.getElementById(‘imgl’).src = ‘imgs/1.png’;”[/B][/COLOR][/CODE]

Thanks in advance ?

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@ZeroKilledJan 21.2009 — because the element is contained on a different document, javascript have to refer that document before getting the element. so, you would use the [b]top[/b] object which is a reference to the most top frame in the hierarchy of frame and then access the proper document:
<i>
</i>onload = 'top.frames["frame_name"].document.getElementById("img1").src = "imgs/1.png";'


you have to replace [i]"frame_name"[/i] with the given name to the document you want to refer.
×

Success!

Help @ATommy 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 6.1,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...