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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T10:10:15+00:00 2026-05-19T10:10:15+00:00

I have several iframes on a page that display ads unicorns/bacon to users. Because

  • 0

I have several iframes on a page that display ads unicorns/bacon to users. Because its not possible to detect an iframe’s domready event via the parent (please let me know if this isn’t true) I have some initialization-code in each iframe like this:

<body data-controller="unicorn">
    <!-- content -->

    <script>
        var $ = parent.jQuery;
        if($ && $.frameReady){
            $(document).ready(function(){
                $.frameReady(document);
            });
        }
    </script>
</body>

The parent document has code very similar to the following (about this technique via @Paul Irish):

var frames = {
    // the following is irrelevant to my question but awesome.
    "unicorn": function (document) {
        var script = document.createElement("script"),
            element = document.getElementsByTagName("script")[0];
        script.src = "http://www.cornify.com/js/cornify.js";
        script.onload = function () {
            // defaultView is the DOMWindow.
            document.defaultView.cornify_add();
            $(document).click(document.defaultView.cornify_add);
            script.parentNode.removeChild(script);
        };
        element.parentNode.appendChild(script, element);
    },
    "bacon" : function(document) { /** mmm, bacon **/ }
};
// relevant but boring...
$.frameReady = function(document){
    var controller = $(document.body).data("controller");
    controller && frames[controller] && frames[controller](document);
};

Here is an example in jsfiddle (you can edit it here). It works great (at least it does in Chrome dev).

Now what I would LIKE to do is get rid of the data-controller bit in the iframe and instead use the id (or data-* or whatever) of the actual iframe element that is in the parent document to initialize the code.

If I could query the DOM via DOMWindow it would look like this:

$.frameReady = function(document){
    var iframe = $("body").find(document.defaultView),
        controller = iframe.data("controller");
    controller && frames[controller] && frames[controller](document);
};

Luckily, I only need this to run on webkit based browsers, Adobe Air 2.5 actually (but I’m testing in Chrome ATM).

Because S.O. answerers like it when a Question has a question here it is:

Is there any (efficient) ways to query the DOM via document or window in webkit-based browsers – including Adobe Air 2.5?

  • 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-19T10:10:16+00:00Added an answer on May 19, 2026 at 10:10 am

    I have now found that one iframe containing the unicorn for you

    console.log(
            $("iframe").contents().filter( function(){
               return this == document
            }).length
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have several apps inside iframes in the page that consolidates the apps (it
I have a C# webbrowser that holds an html page that has several iframes.
I have a page with several iframes. One of this iframes has a page
I have an HTML page with several iframes, each pointing to a text file
I have a page that uses several dijit form widgets. I also have an
I have several iFrames that load an external webpage, although only 1 appears at
I have a page that has several (20+) scripts that are being loaded. One
I have a simple HTML page that rotates through several status pages that I
Is it possible to have a page (or post) in the BLOGGER platform that
I have several HTML elements (buttons) that fire the same JQuery AJAX request. When

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.