Sign in to follow this  
H_o_p_s

[web] Frames and Javascript help...

Recommended Posts

H_o_p_s    877
I'm trying to read parent.location.href within javascript, but so far I've only been able to write it... is it possible to get the parent's location without having a direct name attribute to get it? //EDIT The error seems to be "Error: uncaught exception: Permission denied to get property Location.href" Because evidently it is a security risk to get the location.href of a frame that isn't the same domain as the initializing frame... so I am guessing that this is not possible. Any suggestions would help. [Edited by - H_o_p_s on November 9, 2005 11:02:08 PM]

Share this post


Link to post
Share on other sites
markr    1692
Unprivileged javascript isn't allowed to touch anything that came from a different security domain. This typically means a different host name (if it came via http), or any other protocol.

It's a reasonable security precaution, otherwise a page could simply open a frameset, open gmail in another frame, and start using the DOM methods to read your email, then post it to an attacker's web site.

To make it work, ensure that all the frames are hosted on the same server.

Mark

Share this post


Link to post
Share on other sites
H_o_p_s    877
Alright, so what I was trying to do in this first post was to access the HREF of a parent frame that is located under a different domain. Why I wanted to do this: My domain is masked (from http://www.hopkinsmultimedia.com to my gamedev hosted site) and I wanted to be able to go http://www.hopkinsmultimedia.com/products and have it go to my products page. I had thought that the best way to do this was to write a javascript that would redirect based on this information.

I found that I could do this. I just read the referrer, because the masking frame is always the refferer I could read this information.

For instance goto: http://www.hopkinsmultimedia.com/services. This location does not exist under the domain hopkinsmultimedia.com, but instead my javascript will read the referrer and change the internal frame internally.

The current downside is that when I change pages, the URL does not update. The solution to this would be to change the parent's location.href, but since this requires a full page reload, it takes longer. Since most people will just be visiting the site from the plain URL(http://www.hopkinsmultimedia.com) there should be little confusion.

So overall I think I pulled it off pretty good. Other than the 'connecting to members.gamdev.net' you can't tell that this domain is masked.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this