Tags
Asked 2 years ago
9 Jun 2021
Views 367
Imani

Imani posted

open window and run function on that window

open window and run function on that window


newwindow=window.open("https://www.java.com");
newwindow.callfunction();


i want to send code to the new window and run the function at their to interact with new window content.
Phpworker

Phpworker
answered Apr 27 '23 00:00

You can use window.open() to open a new browser window and then use the window.onload event to run a function on that window after it has finished loading.

Here is an example:



function openWindow() {
  var newWindow = window.open("https://www.example.com");
  
  newWindow.onload = function() {
    // run a function on the new window
    newWindow.document.body.innerHTML = "<h1>Hello, world!</h1>";
  };
}

This function opens a new window with the URL "https://www.example.com" using window. open() . Then, it sets the onload event of the new window to a function that will be called after the new window has finished loading.

In this example, the function sets the inner HTML of the new window's document body to "<h1> Hello, world! </h1> ", which will display a heading on the new window when it is loaded.

You can call the openWindow() f unction to open the new window and run the function on it:



openWindow();

This will open the new window and run the function on it when it is loaded.
Post Answer