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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:04:49+00:00 2026-05-22T15:04:49+00:00

When i open a popup, i want to be able to set few callbacks

  • 0

When i open a popup, i want to be able to set few callbacks that the popup can call.
So basically i’d have two pages with code like this:

*****popup.html*******
var callBack;
function OnSaveClick()
{
  if (callBack)
     callBack();
}

**********************************************
********popupOpener.html*************
function callBackHandler()
{
   //some code here
}
function OpenPopup()
{
   var p = window.open("popup.html");
   p.callBack = callBackHandler;
   return false;
}

The problem with this is that var callBack gets reset when the DOM of popup.html loads and it doesn’t load until OpenPopup() on the opener completes.
So the next best thing would be to set the callBack in the ready event of popup.html. But i want to be able to attach an event handler to the ready event of popup.html in popupOpener.html.
So the OpenPopup function would now look something like this:

var p;
function OpenPopup()
{
  p = window.open("popup.html");
  $(p).ready(hookCallBack)      //doesn't work
  //or $(p.document).ready(hookCallBack)  //doesn't work
  return false;
}
function hookCallBack()
{
  p.callBack = callBackHandler;
}

But hookCallBack() executes immediately after $(p).ready(hookCallBack) and NOT when the DOM of popup.html is ready. Is there any other way to do this?

  • 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-22T15:04:50+00:00Added an answer on May 22, 2026 at 3:04 pm

    See my question: Get DOM elements of a popup for jQuery manipulation for an answer of how to control the popup after it is loaded

    So you can do something like @MattBall’s answer:

    popupOpener.html:

    var opener = {
    
            popup: null, 
    
            newPopup: function(windowsname){
                this.popup = window.open(windowsname);
                var self = this;
    
                this.popup.onload = function ()
                {
                  var doc = this.document,
                      script = doc.createElement('script');
                      script.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js';
                      script.onload = function ()
                      {
                          function setup()
                          {
                              //something to do on the popup
                          }
    
                          script = doc.createElement('script');
                          script.textContent = "(" + setup.toString() + ")();";
                          doc.body.appendChild(script);
                      };
    
                      doc.head.appendChild(script);
                };
            },
    
            some_function: function(){
                 //calling it here:
                 this.newPopup('popup.html');
            }
        }
    

    So to load the popup on page load:

    window.onload = function(){
        opener.some_function();
    };
    

    Here is a demo: http://jsfiddle.net/EJasA/

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

Sidebar

Related Questions

I have an html page. On that page I want to open popup window.
I have a div that I want to write to a popup window (for
I have a need to open a popup detail window from a gridview (VS
I have an application that uses window.open() to generate dynamic popups. Unfortunately, I've had
I have an RTF file that I want to display inside a web page
The problem is that I have two listView but one itemClick method, if I
I can't seem to get the dialog to open to the height I want,
I want to open popup window when browser closed or closed tabs.
I want to open a popup window and disable the parent window. Below is
I want to open a remote url inside a javascript popup instead of doing

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.