2

I have some JavaScript in a page that takes the values passed by a module Window and assigns it to a C# variable, so it can be used within the code behind. So my JavaScript looks like:

The JavaScript

<script type="text/javascript">

       function openSecure(args) {
           var manager = $find("<%= rwmSecure.ClientID %>");
           var domain = '<%=ConfigurationManager.AppSettings("CPCDomain").ToString %>';
           var URL;

           if (domain == 'localhost') {
               URL = 'http://localhost';
           }

           URL += "/WindowPage.aspx?args=" + args;
           manager.open(URL, "rwSecure");
       }
       function OnClientCloseSecure(oWnd, args) {
           var arg = args.get_argument();

           if (arg) {

               var ResultCode = arg.ResultCode;
               document.getElementById("hdnResultCode").value = ResultCode;
               var AuthCode = arg.AuthCode;
               var ReferenceNumber = arg.ReferenceNumber;
               var TransactionID = arg.TransactionID;
               var ErrorCode = arg.ErrorCode;
               var ErrorDescription = arg.ErrorDescription;
               var CardNumber = arg.CardNumber;
               var PONumber = arg.PONumber;
               //document.getElementById('<%=btn.ClientID %>').click();

               __doPostBack('pnlComplete', '');
           }
       }       
</script>

And to clarify this a bit more. The Module window is pulling in a page from localhost, but the Module window is being called from a page on localhost:61156. So once the javascript sets the variavle it also issues a click command on a asp.net button to run some code:

C# Code

protected void btn_Click(object sender, EventArgs e)
{
    if (string.IsNullOrEmpty(hdnResultCode.Value)) {
        dspConfirm();
        pnlComplete.Visible = false;
        pnlConfirm.Visible = true;
    } else {
        dspComplete();
        pnlComplete.Visible = true;
        pnlConfirm.Visible = false;
    }

}

So when I run this I get a javascript error that says:

Unsafe JavaScript attempt to access frame with URL http://localhost/SecurePayment.aspx?args=H4sIAAAAAAAEAOy9B2AcSZYlJi9tynt%2fSvVK1%2bB0oQiAYBMk2JBAEOzBiM3mkuwdaUcjKasqgcplVmVdZhZAzO2dvPfee%2b%2b999577733ujudTif33%2f8%2fXGZkAWz2zkrayZ4hgKrIHz9%2bfB8%2fIr578jMnL09%2b5k3etG%2fqbNlk07aolj%2bzi%2bdndsY7u%2f9PAAAA%2f%2f8VkT5ZIQAAAA%3d%3d&rwndrnd=0.23641548841260374 from frame with URL http://localhost:65116/ShoppingCart.aspx. Domains, protocols and ports must match.
b.RadWindow._registerChildPageHandlersScriptResource.axd?d=vMihE91hOtu6KBE47c3D9AjqD9Il5YI4LpCLhSvp5YZn6p98cl2a_AbJJmNWVZfnmjtLnCnYEoaBHBC919OsikIEmKq8TGOzWNWN_HUBLLo8fW7DdN4EuN3Q076lAa_FOwh_Yk2b3DL-W2Fv0&t=38ec0598:1125
b.RadWindow._onIframeLoadScriptResource.axd?d=vMihE91hOtu6KBE47c3D9AjqD9Il5YI4LpCLhSvp5YZn6p98cl2a_AbJJmNWVZfnmjtLnCnYEoaBHBC919OsikIEmKq8TGOzWNWN_HUBLLo8fW7DdN4EuN3Q076lAa_FOwh_Yk2b3DL-W2Fv0&t=38ec0598:1143
(anonymous function)ScriptResource.axd:47
Sys$UI$DomEvent$addHandler.browserHandlerScriptResource.axd:4048

So is there any possible way around this or way to fix this? I've been scratching my head for two days and I'm ready to throw my keyboard. :) Thanks!

2
  • Seems to be somehow self-contradictory to use javascript to pass variables to a page called SecurePayment and funny that even javascript itself complains about "unsafe JavaScript" ;-) Commented Apr 19, 2012 at 14:46
  • I agree, but its what I've been given to use. :-P Commented Apr 19, 2012 at 14:48

1 Answer 1

2

Your javascript error is pretty informative.

Unsafe JavaScript attempt to access frame with URL http://localhost/SecurePayment.aspx?args=... from frame with URL http://localhost:65116/ShoppingCart.aspx. Domains, protocols and ports must match.

This sounds like an exception with the Same Origin Policy

The policy permits scripts running on pages originating from the same site to access each other's methods and properties with no specific restrictions, but prevents access to most methods and properties across pages on different sites.[1]

and

The term "origin" is defined using the domain name, application layer protocol, and (in most browsers) port number of the HTML document running the script. Two resources are considered to be of the same origin if and only if all these values are exactly the same.

Your script is running on your local machine in a site at a particular port, but trying to access a page on your local machine at a different port. I'd start there.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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