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
- frames['innerFrame'].location.href
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
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
- <title>iframe test</title>
- <script type="text/javascript">
- var alertHref = function() {
- alert(frames['innerFrame'].location.href);
- }
- window.onload = function() {
- // the time out just make sure the iframe is ready
- setTimeout(" alertHref()",3000);
- };
- </script>
- </head>
- <body>
- <iframe src="http://www.thescripts.com"
- id="innerFrame"
- width=1000
- height=500
- name="innerFrame">
- </iframe>
- </body>
- </html>