9

I have a page with an Iframe and a Javascript from Iframe that access to a function of parent frame. The pages are on the same server (it's not cross domain scripting), I'haven't any problem with FF and IE but when I use it on Chrome I have the message below.

Unsafe JavaScript attempt to access frame with URL http://samedomain:51700/irj/servlet/prt/portal/prtroot/CRMApp73.StoricoApp from frame with URL http://samedomain:51700/irj/servlet/prt/portal/prtroot/CRMApp73.CRMOProxy. Domains, protocols and ports must match.

How can I solve this issue? I search by google since 4 hours. I hope someone can help me.

EDIT: code

This is the JavaScript in the iframe page. This JavaScript call a parent frame Javascript function "setUfficioPostale". This is the point where Chrome give me "Unsafe Access..." error.

<script>
    window.parent.setUfficioPostale(map);
</script>

This is the Javascript in the parent frame for form submitting. This is for sending hidden form with hidden params to a page loaded in iframe.

function onAltroUfficioClick(){
    document.getElementById("hiddenParams").submit();
    $('#framePosteMaps').show();
}

This is the iframe definition in the parent page.

<iframe id="framePosteMaps" scrolling="no" name="framePosteMaps"></iframe>

This is the form with target attribute to send parameters to iframe page.

<form id="hiddenParams" target="framePosteMaps" action="http://samedomain:51700/irj/servlet/prt/portal/prtroot/TestFrameRC.SimPerProxy" method="POST">
    <input type="hidden" name="distanza" value="10">
    <input type="hidden" name="cliente" value="Retail">
    ....................
</form>
5
  • Though it sounds like it shouldn't be necessary, perhaps setting document.domain in both parent and iframe to the same value would jolt it into working? Sep 13, 2011 at 17:02
  • notice: if your samedomain are foo.somedomain.com and bar.somedomain.com they are not same.
    – c69
    Sep 23, 2011 at 15:03
  • Is CRMOProxy changing your port?
    – Kevin M
    Sep 30, 2011 at 3:21
  • If "samedomain" is really absolutely the same string AND the iframe is not redirected anywhere, this surely looks like a bug. Btw any reason why you are not using ajax instead?
    – a sad dude
    Jan 14, 2012 at 21:13
  • I have the same issue. However, it only fails for me when on https. I specifically have the iframe src'd as https and the parent page as https but for some reason it still shows the error. Did you every resolve this?
    – Scoota P
    Feb 8, 2012 at 23:02

3 Answers 3

2

The Chrome don't allow you to do that. Code from Iframe cannot access parent code.

2

First, check that both pages are being referenced using the SRC attr of the iframe in exactly the same way, I mean:

http://samedomain:51700/irj/
http://samedomain:51700/irj/

beacause it is possible, that even if they are running in the same machine, one of those iFrames is called like:

http://localhost:51700/irj/

and the other:

http://MachineId:51700/irj/

or any other combination.

You can check it by inspecting the code with the Developer tools in all modern browsers.

Chrome allows you to call parent's function if they are in the same domain (I do it everyday), so there shouldnt be any problem.

I use this function to acces children iFrames:

var getIframe = function (id) {
    if ($.browser.mozilla) return document.getElementById(id).contentWindow;
    return window.frames[id];
};

and just "parent.yourParentFunction()" when you want to access a function in the parent.

Check that the parent's function is assigned to the Window object (global namespace)

Good luck with that :-)

1
  • 3
    Just a little note: it's not a good practice to test for the browser type/version. Test for the feature availability instead! Nov 15, 2011 at 11:21
1

The parent frame may have set a document.domain value different from "samedomain". Update the document.domain property in the iframe js to the value set in the parent frame and it should work.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.