By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,605 Members | 2,137 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,605 IT Pros & Developers. It's quick & easy.

Re: Best way to break out of a frame

P: n/a
On Jul 27, 9:37*pm, Jonas Smith <jonas.sm...@yahoo.comwrote:
When I started my site a long time ago, I found out that some other site
was framing my site and serving ads around it, even though I had no ads.

At the time as a solution (and it worked) I added the following
Javascript statement to all my html files:

<body onload="if (window != window.top) {top.location.href =
location.href;}">

That surely breaks frames.

However, recently, few of my users have complained that the site keeps
reloading when accessed with a blackberry. All pages keep reloading
until stopped. I found the culprit to be the above JS statement.
Here somebody has regurgitated a lot of bad examples in a very bad
color scheme, but there are a couple of useful ideas to be found:

http://perishablepress.com/press/200...es-notes-plus/

Does the Blackberry even support frames? Perhaps it would be useful
to skip the test if window.frames is not a truthy object.

The other thing that escaped me before is window.self. Try comparing
that to window.top instead.
Jul 28 '08 #1
Share this Question
Share on Google+
6 Replies


P: n/a
On Aug 4, 12:30*pm, Jonas Smith <jonas.sm...@yahoo.comwrote:
On Mon, 28 Jul 2008 01:28:02 -0400, Jonas Smith wrote
(in article <488d58e2$0$614$9a6e1...@unlimited.newshosting.com >):
On Sun, 27 Jul 2008 22:48:14 -0400, David Mark wrote
(in article
<92f5db2e-d126-43c3-a770-39c580eb7...@z66g2000hsc.googlegroups.com>):
On Jul 27, 9:37*pm, Jonas Smith <jonas.sm...@yahoo.comwrote:
When I started my site a long time ago, I found out that some other site
was framing my site and serving ads around it, even though I had no ads.
>At the time as a solution (and it worked) I added the following
Javascript statement to all my html files:
><body onload="if (window != window.top) {top.location.href =
location.href;}">
>That surely breaks frames.
>However, recently, few of my users have complained that the site keeps
reloading when accessed with a blackberry. All pages keep reloading
until stopped. I found the culprit to be the above JS statement.
Here somebody has regurgitated a lot of bad examples in a very bad
color scheme, but there are a couple of useful ideas to be found:
>http://perishablepress.com/press/200...es-notes-plus/
Does the Blackberry even support frames? *Perhaps it would be useful
to skip the test if window.frames is not a truthy object.
The other thing that escaped me before is window.self. *Try comparing
that to window.top instead.
Thanks for the pointers, I made some changes and I am now waiting for my
volunteer tester to come back with results.

I'm now using:

<body onLoad="if (window.self!=window.top) {window.top.location =
window.self.location;}">
You are still breaking the back button! That is the single most
annoying blunder that a JS developer can make (see any of Google's
properties for lots of bad examples.) Use location.replace to avert
this problem.
Aug 4 '08 #2

P: n/a
On Aug 4, 6:30*pm, Jonas Smith <jonas.sm...@yahoo.comwrote:
On Mon, 28 Jul 2008 01:28:02 -0400, Jonas Smith wrote
(in article <488d58e2$0$614$9a6e1...@unlimited.newshosting.com >):


On Sun, 27 Jul 2008 22:48:14 -0400, David Mark wrote
(in article
<92f5db2e-d126-43c3-a770-39c580eb7...@z66g2000hsc.googlegroups.com>):
On Jul 27, 9:37*pm, Jonas Smith <jonas.sm...@yahoo.comwrote:
When I started my site a long time ago, I found out that some other site
was framing my site and serving ads around it, even though I had no ads.
>At the time as a solution (and it worked) I added the following
Javascript statement to all my html files:
><body onload="if (window != window.top) {top.location.href =
location.href;}">
>That surely breaks frames.
>However, recently, few of my users have complained that the site keeps
reloading when accessed with a blackberry. All pages keep reloading
until stopped. I found the culprit to be the above JS statement.
Here somebody has regurgitated a lot of bad examples in a very bad
color scheme, but there are a couple of useful ideas to be found:
>http://perishablepress.com/press/200...es-notes-plus/
Does the Blackberry even support frames? *Perhaps it would be useful
to skip the test if window.frames is not a truthy object.
The other thing that escaped me before is window.self. *Try comparing
that to window.top instead.
Thanks for the pointers, I made some changes and I am now waiting for my
volunteer tester to come back with results.

I'm now using:

<body onLoad="if (window.self!=window.top) {window.top.location =
window.self.location;}">

That seems to work with the blackberry browser without reloading.
But why window.self ?

window.self.location === window.window.location === window.location

Or not ?

--Jorge.
Aug 4 '08 #3

P: n/a
On Aug 4, 3:46*pm, Jorge <jo...@jorgechamorro.comwrote:
On Aug 4, 6:30*pm, Jonas Smith <jonas.sm...@yahoo.comwrote:
On Mon, 28 Jul 2008 01:28:02 -0400, Jonas Smith wrote
(in article <488d58e2$0$614$9a6e1...@unlimited.newshosting.com >):
On Sun, 27 Jul 2008 22:48:14 -0400, David Mark wrote
(in article
<92f5db2e-d126-43c3-a770-39c580eb7...@z66g2000hsc.googlegroups.com>):
>On Jul 27, 9:37*pm, Jonas Smith <jonas.sm...@yahoo.comwrote:
>>When I started my site a long time ago, I found out that some othersite
>>was framing my site and serving ads around it, even though I had noads.
>>At the time as a solution (and it worked) I added the following
>>Javascript statement to all my html files:
>><body onload="if (window != window.top) {top.location.href =
>>location.href;}">
>>That surely breaks frames.
>>However, recently, few of my users have complained that the site keeps
>>reloading when accessed with a blackberry. All pages keep reloading
>>until stopped. I found the culprit to be the above JS statement.
>Here somebody has regurgitated a lot of bad examples in a very bad
>color scheme, but there are a couple of useful ideas to be found:
>>http://perishablepress.com/press/200...es-notes-plus/
>Does the Blackberry even support frames? *Perhaps it would be useful
>to skip the test if window.frames is not a truthy object.
>The other thing that escaped me before is window.self. *Try comparing
>that to window.top instead.
Thanks for the pointers, I made some changes and I am now waiting formy
volunteer tester to come back with results.
I'm now using:
<body onLoad="if (window.self!=window.top) {window.top.location =
window.self.location;}">
That seems to work with the blackberry browser without reloading.

But why window.self ?
The OP seems to have settled on a pattern that works by coincidence.

This seems like a practical solution.

<body onload="if (window.self != window.top)
{ window.top.location.replace(window.location.href); }">

Of course, the location.replace method should be feature tested.

Also, there would seem no need to do this test at all if there is no
window.frames or window.frames.length is zero.




Aug 4 '08 #4

P: n/a
On Aug 4, 10:37*pm, David Mark <dmark.cins...@gmail.comwrote:
>
Also, there would seem no need to do this test at all if there is no
window.frames or window.frames.length is zero.
window.frames or window.top.frames ?

--Jorge.
Aug 4 '08 #5

P: n/a
On Aug 4, 5:05*pm, Jorge <jo...@jorgechamorro.comwrote:
On Aug 4, 10:37*pm, David Mark <dmark.cins...@gmail.comwrote:
Also, there would seem no need to do this test at all if there is no
window.frames or window.frames.length is zero.

window.frames or window.top.frames ?

--Jorge.
You could test if window.frames is a truthy object, and
window.frames.length is a number. A more direct test would also check
that window.top.frames.length is non-zero.
Aug 4 '08 #6

P: n/a
On Aug 11, 1:32*am, Jonas Smith <jonas.sm...@yahoo.comwrote:
[snip]
>
OK, by now my inexperience in this issue should be apparent.
Yes.
>
Can you explain what you what you mean?
I mean stop breaking the back button. If you click the back button
and your browser does a U-turn back to the page you were on, the
previous page broke the back button. It's a really stupid thing to do
and will annoy your users to no end.
>
First you complain about breaking the back button and then when I say
don't care about that part, you state that I should and somehow if I do
Of course you should. Why would you want to break your users' agents?
care about the back button and do it your way, my readers won't get back
to the offending site. How does that work exactly?
You have been told at least three times.
>
I don't break the button but the reader doesn't get back to the other
site by clicking the back button? To me that sounds a little
paradoxical.
It isn't. Try it and you'll see.
Aug 11 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.