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 7399619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:05:01+00:00 2026-05-29T04:05:01+00:00

Basically I have an iframe loaded that is accessed from the parent whenever it

  • 0

Basically I have an iframe loaded that is accessed from the parent whenever it trigger the onload event. It works fine but I’m getting errors when the contents of the iframe are no longer on the same domain, which is to be expected.

Only thing is, I’d like to suppress these errors. Unfortunately a try/catch doesn’t catch this exception and trying to access any of these properties to validate them produces the same error again, thus defeating the purpose.

Is there a reliable way for me to simply check if the iframe contents are accessible without producing any error messages?

Thanks

Edit:

For the sake of context and not having people answer with irrelevant comments; I am writing a small script that auto resizes the iframe on the parent page based on the height of the iframes document. When a user clicks a link inside the iframe that points outside the domain I obviously won’t be able to detect the height of the page, but I’d prefer not to trigger any errors in the console and instead handle the exception gracefully.

I am aware that there are workarounds available, I am simply trying to educate myself by figuring out if there is a graceful way to handle these kinds of cases, rather than just resorting to an ugly workaround.

  • 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-29T04:05:02+00:00Added an answer on May 29, 2026 at 4:05 am

    If you can add a little JavaScript to all of the pages from your domain you’d like to load in the iframe you could use window.postMessage, which is exempt from the Same Origin Policy. Probably the simplest way would be to have the child window post a message to the parent when it loads and use that instead of onload. For example, you could add this to each page:

    if (window.parent) document.addEventListener( 'load', function() {
        window.parent.postMessage( "child loaded", "/" );
    }, false );
    

    That will post a message to the parent window whenever the page is loaded in a frame with the same origin. You would then listen for it like this:

    var iframe = document.getElementById( 'your-iframe' );
    var origin = window.location.protocol + '://' + window.location.host;
    if (window.location.port != 80) origin += ':' + window.location.port;
    
    window.addEventListener( 'message', function (event) {
        if (event.source != iframe.contentWindow
                || event.origin != origin || event.data != "child loaded")
            return;
    
        // do here what you used to do on the iframe's load event
    }, false );
    

    Note that the examples use the W3C/Netscape event API and thus won’t work in Internet Explorer before version 9.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What a mouthful. Basically I have a parent <div> and inside that an <iframe>
http://jsfiddle.net/fJkBU/1/ That's my code. Basically, I have an iFrame whose source may change. I
I'm trying to create a widget (which is basically an iframe) that would have
Basically, I have an iframe of a page from another domain, and I want
I'm trying to detect when an iframe and its content have loaded but not
I have an iframe that contains a page that is constantly updating (basically a
Basically I have a page that launched a fancybox iframe. In that iframe I
I have basically the opposite problem to this question: How to prevent iframe from
I have a page that contains a dynamically loaded <iframe> . This iframe contains
I have an iframe that I wanna update every 20 seconds. So basically, the

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.