Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6200625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:24:13+00:00 2026-05-24T04:24:13+00:00

We have some code that is making use of the new postMessage functionality in

  • 0

We have some code that is making use of the new postMessage functionality in HTML 5 to work around cross-domain communication issues. I’m trying to find a way to detect whether I’m posting messages to an iFrame that loaded its contents correctly. If the frame fails to load correctly, postMessage doesn’t know this and will happily post messages into an unresponsive frame (I assume since the messages are being delivered to the frame, regardless of whether or not it’s contents loaded).

This is our workflow:

  1. User loads http://www.a.com/specialpage.aspx
  2. a.com/specialpage.aspx in turn loads a child iFrame with it’s source set to a proxy page from another domain, say http://www.b.com/lookatmyproxy.htm as an example.
  3. User does some action, clicks a button
  4. window.postMessage is used to post a message to the child frame, where it is (hopefully) picked up by the proxy that the frame loaded (b.com/lookatmyproxy.htm). After it is received, the message is validated, processed, and the reply is posted back to the parent frame (a.com/specialpage.aspx).
  5. User is shown the results of their action, everyone is happy.

The problem scenario is that if b.com is down and the proxy fails to load inside the iFrame, postMessage will just fire and forget and the parent frame never receives an error or reply of any kind. The security concerns and nature of iframes seem to prevent me from checking the frame contents or status to find out if the proxy loaded correctly. I could put a relay with some timeout logic that we are in control of in between a.com and b.com (a.com posts to a.com/relay, which in turn posts to b.com/proxy, etc.), but that seems overcomplicated.

Is there a way for me to either check the iFrame and tell that it’s contents loaded correctly, or detect that postMessage is delivering to a frame whose source failed to load?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T04:24:14+00:00Added an answer on May 24, 2026 at 4:24 am

    It’s not the cleanest answer but I was able to fix my problem. What I found was some old documentation that, while security does not let you read info from other frames, you can call some functions. In older browsers this was used to trick frames into setting each other url fragments and causing actions to happen. A good reference is here:

    http://softwareas.com/cross-domain-communication-with-iframes

    Since postMessage is allowed, the first thing my proxy does is post a “loaded” message to its parent frame if it exists. The proxy looks something like this:

    //tell the parent that we're functional
    var data = '{ "action" : "Loaded" }';
    if (parent && parent.frames && parent.frames[0] && parent.frames[0].content) {
        parent.frames[0].content.postMessage(data, '*');
    }
    
    window.addEventListener("message", function (e) {
        if (e.domain == undefined) {
            //do something
        }
    }, false);
    

    On the other side of things, my pages listen for that message and set a variable when they receive it to show that the proxy loaded correctly. If they never receive the message, all actions assume the proxy is unavailable and the UI reacts accordingly to block user actions. That looks something like this:

    $(document).ready(function () {
        window.addEventListener("message", function (e) {
            var args = (e.data && (e.data.length > 0)) ? JSON.parse(e.data) : {};
            if (args.action) {
                if (args.action == 'Loaded') {
                    if (typeof ProxyLoaded_success == 'function') {
                        ProxyLoaded_success(args);
                    }
                } 
            }
        }, false);
    });
    
    var proxyLoaded = false;
    function ProxyLoaded_success(args) {
        proxyLoaded = true;
    }
    
    function abc() {
        if(proxyLoaded == true) {
            //do something here
        } else {
            alert("proxy didn't load. call support");
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code that effectively does this : File file = new File(C:\\Program
I have some code that gives a user id to a utility that then
I have some code that uses the shared gateway pattern to implement an inversion
I have some code that raises PropertyChanged events and I would like to be
I have some code that looks like: template<unsigned int A, unsigned int B> int
I have some code that generates image of a pie chart. It's a general
I have some code that I am putting in the code-behind of a master
I have some code that uses the Oracle function add_months to increment a Date
I have some code that prints out databse values into a repeater control on
I have some code that produces a set of primary key values that I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.