Forum Moderators: open

Message Too Old, No Replies

location.hostname denied.

Do not have permission for location.hostname

         

Armadillo

7:21 am on Aug 10, 2008 (gmt 0)

10+ Year Member



I am attempting to prevent my framed page from being loaded outside of its frame, or within the frame of another site.
I have tried this code.

if (top == self ¦¦ (top.location.hostname!=self.document.location.hostname))
window.location.href = 'http://mysite.com/photos.html';

and this code.

if (top == self ¦¦ ((top.location.hostname != 'mysite.com')&&(top.location.hostname != 'www.mysite.com')))
window.location.href = 'http://www.mysite.com/photos.html';

In both cases, it prevents the page from loading outside the frame. But it allows the page to be loaded within a frame on another site in both IE7 and FF3.
The FF error console says permission is denied for location.hostname.
I know this used to work, so I'm guessing new browsers have some security preventing this. Is there any way around the issue?

daveVk

10:51 am on Aug 11, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Security probably preventing this: top.location.hostname. Try catching error, something like.

try
{
if (top == self ¦¦ (top.location.hostname!=self.document.location.hostname))
window.location.href = 'http://mysite.com/photos.html';
}
catch(err)
{
window.location.href = 'http://mysite.com/photos.html';
}

Armadillo

7:08 am on Aug 12, 2008 (gmt 0)

10+ Year Member



Cool.
I used top.window.location.href to prevent an endless reload loop in a frame, but it worked.
Thank you very much.