Forum Moderators: open

Message Too Old, No Replies

Check browser's frame support from script?

javascript to check if browser supports frames

         

antonbijl

9:16 am on Jun 28, 2004 (gmt 0)

10+ Year Member



Hi all

I have a frames website.

I'm using a script similar to the one in this thread [webmasterworld.com...] to force content pages to load inside the frameset.

I've added <noframes> tags on every content page. Inside these tags I have basic links to every other content page. The (desired) result is that a user with a noframes browser should see a fully functional website with all the content and should be able to browse to other content pages using the links defined inside the <noframes> tags on every content page. (frames-supporting browsers will not see these links and will use a navigation toolbar in another frame to navigate instead)

The problem is the script forces the frameset to be loaded, but on a noframes browser this results in a blank page being shown. So I now want to enhance that javascript to only force the frameset to load if the browser supports frames (thus enabling a noframes user to still view all content).

Please note: Don't tell me to only put noframes tags on the frameset page, I want noframes users to see content! The noframes tags as I've implemented them work perfectly and when I disable the javascript that forces the frameset to load, both the noframes and frames versions render exactly as I want them. however, I don't want a frames-supporting browser to load a page without the frameset.

Question is: How do I check for frames support from within that javascript?

Cheers

Anton

Bernard Marx

9:58 am on Jun 28, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't have a browser without frames to test.
A quick thought:

[blue]<script>
var supportsFrames = true
</script>
<noframes>
<script>
supportsFrames = false
</script>
</noframes>
<script>
alert("The proposition that I support frames is " + supportsFrames)
</script>[/blue]

antonbijl

10:23 am on Jun 28, 2004 (gmt 0)

10+ Year Member



Bernard

Thanks, I have actually tried something similar, but for some reason (as yet undetermined) it didn't work. I'll go back and debug my code a bit.

I'll test your suggestion, thanks a lot. I would still prefer if there was a standard js function that I could use, but it seems there is no such thing.

Cheers

Anton

Bernard Marx

10:32 am on Jun 28, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It should work, and seems simple enough - but as frames user, how would I know?

Another approach could be to check for the collection..if( --- ):

document.frames //sometimes...
window.frames // (and, no, that's not a pun)

antonbijl

12:39 pm on Jun 28, 2004 (gmt 0)

10+ Year Member



Bernard

I've tested your code above and it does work (BTW, I use Opera to test for noframes compatibility, since it allows you to switch frames support off). However, my version still isn't working. At least the concept is proven though, I'll just have to debug my code a bit further. If I don't get it right soon, I'll post back for your advice (unfortunately my javascript isn't very hot)

Cheers and thanks for the help.

Anton

antonbijl

1:52 pm on Jun 28, 2004 (gmt 0)

10+ Year Member



Bernard

Thanks for your input, I've got it working now.

Anyway, for anyone else interested, the final code (on the content page) that worked for me looks something like this:


<script>
var framesupport = true
</script>
<noframes>
<script>
framesupport = false
</script>
</noframes>
<script>
if (framesupport == true) {
currentURL=top.location.href;
contentIndex = currentURL.indexOf('?');
myContentURL=currentURL.substring(contentIndex+1, currentURL.length);
passpage = document.URL;
if (top.location==self.location) {
top.location.href="index.htm?"+passpage;
}
if (top.location!=self.location && contentIndex>-1 && myContentURL!=passpage) {
top.location.href="index.htm?"+passpage;
}
}
</script>

Rambo Tribble

2:11 pm on Jun 28, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You may wish to note that support for frames, as opposed to iframes, happened in the same versions of Netscape and IE that support for JavaScript was introduced. (NN2, IE3)

antonbijl

4:07 pm on Jun 29, 2004 (gmt 0)

10+ Year Member



Rambo

good point

However:
1 - If the browser doesn't support javascript either, this wouldn't be a problem since the script that forces the frameset to load wouldn't work anyway. So for browsers that support neither frames nor javascript - no problem. Only problem is with browsers that support js, but not frames. Browsers that support frames, but not js is a different thing altogether, though I can't imagine why anyone would do this?
2 - There are other browsers out there too. Opera for instance allows the user to switch off frames support. Mozilla (+ Firefox), Mosaic, Konqueror etc.
3 - As far as noframes support is concerned, I'm actually more concerned about search engine spiders than real people with browsers. Most people nowadays have frame support on their browsers. However, noframes have to be catered for to optimise search engine rankings and to cater for new technologies (how many cell phones have enough space on screen to display frames?)

Cheers

Anton

Bernard Marx

5:04 pm on Jun 29, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



though I can't imagine why anyone would do this?
(Frames, but JS)

Security reasons, I guess. By themselves, frames aren't a threat. Scripting is.