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

How to solve cross domain permission with server proxy?

P: 54
Hi,

I`m trying to read the href property of an iframe with a javascript that running in the main frame. When the main frame and the inner iframe are both from the same domain I can read it with:
Expand|Select|Wrap|Line Numbers
  1. frames['innerFrame'].location.href
but when the inner frame is served from a different domain I run into cross domain permission issues.

Can I use proxy on my server to solve it?
For example let`s say the main frame urs is http://www.example1.com and the inner frame url is http://www.example2.com.
Can I use my server to let the client browser "think" the main frame is from www.example2.com?
Maybe there is another way around this?

I`m using Apache and I realize it`s not a pure javascript question but it`s related.

Here is a short example to reproduce the cross domain permission issue:

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  2. <html>
  3.     <head>
  4.         <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  5.         <title>iframe test</title>
  6.         <script type="text/javascript">
  7.             var alertHref = function() {
  8.                 alert(frames['innerFrame'].location.href);    
  9.             }    
  10.             window.onload = function() {
  11.                 // the time out just make sure the iframe is ready
  12.                 setTimeout(" alertHref()",3000); 
  13.             };
  14.         </script> 
  15.     </head>
  16.     <body>
  17.         <iframe src="http://www.thescripts.com"
  18.             id="innerFrame"
  19.             width=1000
  20.             height=500
  21.             name="innerFrame">
  22.         </iframe>
  23.     </body>
  24. </html>
  25.  
Thanks
Sep 18 '07 #1
Share this Question
Share on Google+
5 Replies


acoder
Expert Mod 15k+
P: 16,027
You could use Ajax to make a request to your web server proxy. The proxy would then deal with making the request to the domain.
Sep 18 '07 #2

P: 54
Could you explain a bit more?

Thanks

You could use Ajax to make a request to your web server proxy. The proxy would then deal with making the request to the domain.
Sep 18 '07 #3

acoder
Expert Mod 15k+
P: 16,027
You could use Ajax to make a request to your web server proxy. The proxy would then deal with making the request to the domain.
Since this is not possible with Javascript, use a server-side script to make the requests/connections. It gets the response and this would become available to the client-side Javascript via the XMLHttpRequest object.

Why do you want the href of the iframe or is that only a test?
Sep 19 '07 #4

P: 54
I want to know when the href of the iframe changes and to read it`s value. It`s not just a test. I have to do it with javascript and I have a feeling it`s possible with setting reverse proxy of the main frame to be the same domain as the iframe.

Thanks


Since this is not possible with Javascript, use a server-side script to make the requests/connections. It gets the response and this would become available to the client-side Javascript via the XMLHttpRequest object.

Why do you want the href of the iframe or is that only a test?
Sep 19 '07 #5

rnd me
Expert 100+
P: 427
the big issue here is that frames cannot talk to one another.
so, the info will have to take an alternate route be it the clipboard, an external file, or a server. you you can control scripts on both pages, you can set an onbefroeunload type event to update youre apache server that the frame navigated away, the hard part would be saying where it went. the simplest way could be to make a new image, and set its source to ping your server.
google image pinging...

you would then need to peroidically check the server from the master page to figure out when they left, since the server cannot 'push' info to the browser...
Sep 21 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.