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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:36:07+00:00 2026-06-05T20:36:07+00:00

Want to run javascript function from parent window in child window Example I have

  • 0

Want to run javascript function from parent window in child window

Example

I have to different websites let’s say site1.com and site2.com

I want from site1.com to open new window of URL site2.com

new_window = window.open("site2.com/index.php", "window2");

Then i want to run a js function test() on this new_window.

// Where site2.com/index.php 
<html>
    ......
</html>
<script>
   function test(){
    // some code here
   }
</script>

Summary

Want to open new window (child) and run some JS functions from parent window.

  • 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-06-05T20:36:10+00:00Added an answer on June 5, 2026 at 8:36 pm

    You can use cross document messaging to circumvent the same origin policy as follows.

    Parent window (site1.com):

    var site2 = window.open("http://site2.com");
    site2.postMessage("test", "http://site2.com");
    

    Child window (site2.com):

    function test() {
        // some code here
    }
    
    window.addEventListener("message", function (event) {
        if (event.origin === "http://site1.com") {
            var funct = window[event.data];
            if (typeof funct === "function")
                funct();
        }
    }, false);
    

    This is a simple example. You could make it more sophisticated to allow callbacks, return values, etc. but that would require a blog post to be fully explained.

    You may read more about window.postMessage on the Mozilla Developer Network.

    Note however that the following example will not work in Internet Explorer (obviously).

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

Sidebar

Related Questions

I want to run a simple JavaScript function on a click without any redirection.
I want to run Protovis javascript from Java and get the evaluated SVG code.
I want to run a javascript one time. I tried using a script from
Is it possible to run Javascript inside an Ember View Handlebars template? I want
I have a HTML table which I add items to from javascript on an
I want to call browser window resize method using jquery from with in iframe.
i have a button1_click() function which runs on page load,,now i want to call
I am using javascript function for copy/paste (CRTL+V) in textbox. Local run of the
I want to have horizontal lists that can run as wide as possible but
I want to prevent a form from being submitted using jQuery and instead run

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.