/    Sign up×
Community /Pin to ProfileBookmark

Retrieve noframes content

Does anyone know how to retrieve a part of the <noframes> content of a frameset using JavaScript?

[code=html]<frameset cols=”*,*” frameborder=”NO” border=”0″ framespacing=”0″>
<frame src=”left.html” name=”leftFrame” >
<frame src=”right.html” name=”rightFrame”>
<noframes>
<body>
<p id=’noFramesText’>I want to retrieve this text</p>
</body>
</noframes>
</frameset>[/code]

I want to dynamically place the text in the frame named ‘leftFrame’. All pages belong to the same domain.
This code inside [B]left.html[/B] doesn’t seem to work:

[CODE]window.onload = function()
{
var noFramesText = top.document.getElementById(‘noFramesText’);
alert(noFramesText);
}[/CODE]

to post a comment
JavaScript

11 Comments(s)

Copy linkTweet thisAlerts:
@KorJan 21.2006 — <noframes> is an escape tag to show something in the main page if the frames are not supported by the browser. Now, how can you logically think that you may call and write someting on a frame inside a tag which is designed to to something if the browser don't support frames? :rolleyes:

can you detail your problem?
Copy linkTweet thisAlerts:
@mmotestauthorJan 21.2006 — Every modern browser supports frames, from that point of view the <noframes> tag is obsolote. However, it now serves an important function in helping search engines index a framed website. At least that's what I'm using it for.
Copy linkTweet thisAlerts:
@KorJan 21.2006 — 
it now serves an important function in helping search engines index a framed website. At least that's what I'm using it for.
[/quote]

Search engines do not follow a Javascript code. At least not as far as I know.
Copy linkTweet thisAlerts:
@mmotestauthorJan 21.2006 — I know, search engines do not follow JavaScript code, but the text I want them to index, is embedded in normal HTML. JavaScript is only being used to 'transport' the text into a different frame so I will only have to load it once (it's quite long).
Copy linkTweet thisAlerts:
@KorJan 21.2006 — I understand now. But the browsers without frames "enabled" usually do not know much about javascript ... So that I guess that a server-side application would do that for you...., not a client-side such as javscript.
Copy linkTweet thisAlerts:
@mmotestauthorJan 21.2006 — You don't understand: this is not about browsers that don't understand frames or have JavaScript disabled, it's about search engines and saving bandwith.

It would be a breeze to do this with PHP, but the visitor would have to load a large chunk of text every time one frame reloads. It is much more efficient to store that text in the 'fixed' part of the window and load it only once, at the same time making that text easily findable for search engines.

Again: I'm assuming the visitors browser understands frames and has JavaScript enabled.
Copy linkTweet thisAlerts:
@felgallJan 21.2006 — What about the 10% of visitors who don't have Javascript enabled? Don't rely on Javascript for anything important, use it only to enhance your web page functionality.
Copy linkTweet thisAlerts:
@CharlesJan 21.2006 — Ahh, but you'll end up with a site that requires JavaScript, very bad.

Best to not use frames. Barring that, make sure that your frame pages can each stand alone and then use the NOFRAME element to provide redundant navigation. Search engines will follow that liink and spider your page.

And please note, your frameset page is invalid on at least two points. You need to include a DOCTYPE and you need to omit the BODY element.
Copy linkTweet thisAlerts:
@mmotestauthorJan 21.2006 — Stephen: The main content of the site will still be visible for visitors that have JavaScript disabled, I'll see to that. The script will only enhance the contents.

Also, I know that it is safer not to use frames at all, but I feel that for this particular site, frames are the best solution.

Charles: You're right, the <body> tag shouldn't be there, but either way the script doesn't work. The page does have a 'frameset' doctype.
Copy linkTweet thisAlerts:
@FromU2MEJan 21.2006 — So you want to access a HTML-code that only will be visible to the user if frames aren't supported?

Shouldn't be so hard... use a function [B]outside <frameset>[/B] that you can call from different frames/documents and as many times you want. ?

[code=php]<html>
<head>
<title>Your title</title>

<script type="text/javascript">

var 2print = "I want 2 b printed<p>";
2print += "...and so do I";

function printMe(id) {

if (id == "noFrame") {
document.getElementById("noFramesText").innerHTML = 2print;
}
else {
document.write(2print);
}

}

</script>

</head>

<frameset cols="*,*" frameborder="NO" border="0" framespacing="0">
<frame src="left.html" name="leftFrame" >
<frame src="right.html" name="rightFrame">

<noframes>
<body onload="printMe('noFrame')">
<div id="noFramesText">I want to retrieve this text</div>
</body>
</noframes>
</frameset>[/code]
...and the left.html-code should be...

[code=php]<html>
<head>
<title>ME</title>
</head>
<body>

<script type="text/javascript">
top.document.printMe('do');
</script>

</body>
</html>[/code]

And... as far as I know <body> should be placed within <noframes> (unless maybe in XHTML - not very updated in the frames-matter there though...)
Copy linkTweet thisAlerts:
@mmotestauthorJan 22.2006 — We're getting closer but the text is now embedded in JavaScript, making it visible to 90% of the visitors but not to search engines.

After some test I can only conclude that JavaScript is not able to access html tags inside the <noframes> part and I was hoping someone would prove me wrong...
×

Success!

Help @mmotest 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.18,
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,
)...