473,692 Members | 2,747 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

busting out of frames with javascript in a way that works with all browsers?

I did a little searching for javascript code that will make a page
"jump out" of frames when the page is loaded. There seems to be many,
many ways to do this and I've added the ones I found to the end of
this post.

Which one should I use? Is there a generally accepted "best" way to
do this that works will all browsers?

....
Krick

if (top != self) {
top.location = self.location;
}

if (window != top) {
top.location.hr ef = location.href
}

if (top.window != window) {
top.location.hr ef = window.location .href
}

if (parent.frames. length > 0) {
parent.location .href = location.href;
}

if (top.location != location) {
top.location.hr ef = document.locati on.href
}

if (parent.frames. length >= 1) {
window.top.loca tion.href = "index.html "
}
Jul 23 '05 #1
5 6744
On 5 Oct 2004 15:00:10 -0700, William Krick wrote:
..Sub: busting out of frames with javascript in a
way that works with all browsers? ... Is there a generally accepted "best" way to
do this that works will all browsers?


No. Not all browsers have JS enabled.
(I just wanted to check that you realise that.)

As for the ways to break out of frames in JS enabled browsers,
I'll be listening to what the experts say, and looking over
your suggestions. I am sick of serving up content for other
people's sites, and anything that can reduce that is most welcome.

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.lensescapes.com/ Images that escape the mundane
Jul 23 '05 #2
William Krick wrote:
I did a little searching for javascript code that will make
a page "jump out" of frames when the page is loaded. There
seems to be many, many ways to do this and I've added the
ones I found to the end of this post.

Which one should I use? Is there a generally accepted
"best" way to do this that works will all browsers?
If you are breaking out of frames they will presumably be other people's
frames and cross-domain/same-origin security restrictions will apply.
The extent to which you can read properties of the containing frame may
be more or less restricted because of this.

It is important that your code does not cause an exception due to
security restrictions else it will not only not escape the frame, but it
might not work properly at all.
if (top != self) {
(top != self) and (top != window) are equivalent, as are (parent !=
self) and (parent != window). Top, self, window and parent are
properties of your global/window object so there should be no problem
reading them and comparing them.
top.location = self.location;
This might error because the - location - property refers to an object.
Although you can (and probably should) set it with a sting value this
assignment is setting it to an object reference. Probably the -
self.location - object reference will be type-converted to a sting for
the assignment, but I wouldn't want to trust to that in this context.
Instead assign the - href - (string) property of your location object to
the location property of the top or parent frame:-

top.location = self.location.h ref;
-or:-
parent.location = window.location .href;
(and related permutations)

- assigning to the - location - property in the parent/top frame is not
normally a security issue as at just unloads and replaces the entire
parent/top document.
}

if (window != top) {
top.location.hr ef = location.href
Assigning to the href property of the - top.location - object might be
subject to security restrictions (you may be denied access to the
contents of top.location, or read access to top itself (you have to have
read access to resolve - top.location - to an object reference)).
if (top.window != window) {
top and top.window should refer to the same object, but trying to read
properties of top might be restricted.
top.location.hr ef = window.location .href
}
This assignment is functionally equivalent to the previous example.
if (parent.frames. length > 0) {
Reading properties of the - parent - and/or - parent.frames - object may
be subject to security restrictions.
parent.location .href = location.href;
}

if (top.location != location) {
As indeed might comparing properties of the - top - or - parent - object
with properties of your own global/window object, if they are from
different domains.
top.location.hr ef = document.locati on.href
}

if (parent.frames. length >= 1) {
Again, reading properties of the - parent - and/or - parent.frames -
object may be subject to security restrictions.
window.top.loca tion.href = "index.html "
}


There is more maintenance in using string literals (different code on
each page and a need to update it if you decide to change the page name
(or copy and paste to create a new page). While not only do versions
that assign location.href not need to know their file name, they can all
be imported with a common site-wide JS file.

Compare the self or window properties of your global/window object with
its top or parent properties and if they differ assign the location.href
string from your global/window object to the location property of the
top or parent object. Something like:-

if(parent != window){
parent.location = location.href;
}

Richard.
Jul 23 '05 #3
JRS: In article <cj************ *******@news.de mon.co.uk>, dated Wed, 6
Oct 2004 00:13:52, seen in news:comp.lang. javascript, Richard Cornford
<Ri*****@litote s.demon.co.uk> posted :

If you are breaking out of frames they will presumably be other people's
frames and cross-domain/same-origin security restrictions will apply.
The extent to which you can read properties of the containing frame may
be more or less restricted because of this.

It is important that your code does not cause an exception due to
security restrictions else it will not only not escape the frame, but it
might not work properly at all.

If one's page has without permission been framed, one may want to de-
frame it. But if one cannot de-frame it one might prefer not to display
it at all, or to display a considerably different content ...

Pseudo-code :

if (framed) and (not-authorised) then
body.HTML = "<big>Frame d display not permitted!<\/big>"
// which should stop what follows it from showing.

Or even if (framed) and (not-authorised) then while true do ;

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #4
On Wed, 6 Oct 2004 15:25:04 +0100, Dr John Stockton
<sp**@merlyn.de mon.co.uk> wrote:

[snip]
Or even if (framed) and (not-authorised) then while true do ;


But wouldn't that punish the user by hanging the browser? It wasn't their
decision to steal your page.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #5
JRS: In article <opsfh1a50rx13k vk@atlantis>, dated Thu, 7 Oct 2004
12:07:03, seen in news:comp.lang. javascript, Michael Winter <M.Winter@bl
ueyonder.co.inv alid> posted :
On Wed, 6 Oct 2004 15:25:04 +0100, Dr John Stockton
<sp**@merlyn.d emon.co.uk> wrote:

[snip]
Or even if (framed) and (not-authorised) then while true do ;


But wouldn't that punish the user by hanging the browser? It wasn't their
decision to steal your page.


Well, is there not always a way to stop the browser window? Back, Stop,
Home, or wait for a browser timeout? There should be.

It's an indirect way of punishing the offender, by getting his readers
seriously annoyed with the consequences of unauthorised framing, so that
they become ex-readers.

But I leave it to the reader of my news article to decide what his pages
should do - quietly unframe his page, quietly decline to display,
complain and display, sweep the background through an inartistic choice
of colours, seize up, ...

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1880
by: les | last post by:
Hello, I just wonder what are the implications to use frames to build portal. I've seen some sites that are quite fast with frames but I just wonder if there are hidden "costs". I've tried to use in the past and I run into a lot of problems when I worked with environment where there were frame and no frames pages. Please let me know if frames are OK to use for serious portal.
1
2853
by: Bill H | last post by:
I run a dbms application that interfaces with the web. This module creates a frames page with two frames ('main' and 'mwinfoframe'). All communication with the dbms is routed through the 'mwinfoframe' (it's sort of hidden in that it is assigned 1% (so I can view it in IE). I'm having problems with Firefox working properly while both IE 6 and Netscape v7.x work as expected. The following is additional information. A list of reports...
3
2444
by: Jan Ebbe Jensen | last post by:
Hi I have tried the following code. It works in Mozilla. In IE I'm not able to enable DesignMode? What have I done wrong? It says that obj is undefined? Can anyone help me please.
20
25001
by: Tammy | last post by:
What would be a good alternative to using frames? I need something that will section my webpage into two halves and can change both frames on a single click. Thanks in Advance, Tammy
5
16587
by: Dfenestr8 | last post by:
Hi. I'm designing a site, and I'm trying find a way of browsing it without using frames, so I can test the <noframes> </noframes> tags. I use a linux mandrake 10 system, with KDE 3.2. Is there a browser for linux that doesn't use frames? Or is it possible to configure either firefox or konqueror to not use frames?
11
2585
by: Jamie Dulaney | last post by:
I'm working on a website that uses frames. Some of the pages that belong in the 'main' frame (not the header (top) or contents (side)) need to be SSL encrypted. I have no problems in invoking these pages using SSL (within their respective frame). However, I would like the 'security lock' at the bottom to be present when the frame (main content frame) is showing a secured page. My hunch is that because the other two frames are not SSL...
3
2466
by: qwerty | last post by:
I´m new to ASP.Net. My workmate has some experience with it. He claimed that in ASP.Net working with frames is much simpler than it was ASP. I asked explanation but he couldn't give me such. (a button inside a-tag with attribute target isn't anything new relating ASP.Net, its same old HTML). He claimed that you could change another page´s controls´s property´s value from another frame by using this method: ' Page "Bottom"
1
2784
by: Keimo Repo | last post by:
Hello I would need some advice, even just speculations... A customer of ours insists on a couple of customer specific design features for our existing multi-customer web application: - A top header with a dropdown menu which does not scroll when the page is scrolled. - A lower detail part of the screen (table) where the headers stay, and
12
1132
by: MartinRinehart | last post by:
They just don't get no respect. "In the early days of JavaScript, multiframe and multiwindow web applications were fairly common. Now, web design has turned strongly against the use of frames (but not inline frames, called <i>iframes)</ i>, and it is less common to see web sites that use interacting windows." (Flanagan, 5e; footnote, p. 289) Why?
0
8611
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9094
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8970
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8814
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6468
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4332
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4565
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2989
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2244
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.