Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

244
Views
Cannot get reference to one page from another

I am working on a web app that needs to have two parts. The one is a controller and the other is a display. Something like Google Slides in presentation mode. The controller has a button to launch the display:

<script language="JavaScript">
function OpenMain()
{
    var MainPage = window.open("TheUltraSignalLite.html");
    TimerIMG = MainPage.document.getElementById("TimerIMG");
    TimerIMG.src = "TM-Full-Blue.jpg";
}
</Script>

The call to window.open seems to return null. I have tried Chrome, Edge, Firefox, and Opera and they all have the result. These are all local files for now, but I might put in on a web server someday. I have seen some answers that want you to turn off security, but I cannot ask everyone who uses this app to turn off security. How do I get a valid reference to the display window?

Edit 1: Yes, window.open from the local disk does cause a CORS restriction. I tried this where both files are in the same AWS S3 Bucket, so the CORS should not be an issue. But I still get a null on the window.open. If I put a breakpoint on the first line, then everything worked. If I split the open and the rest of the code into two functions with two buttons, it works. So it looks like I have to find a way to run the open in an async way.

Edit 2 My solution to keep it simple was to put the window.open in the OnLoad event. This opens the child window and allows it to fully render and the value of MainPage is ready to use. (I changed the MainPage to a global variable.) I still have to run it from some type of web server, rather than loacl file, but that is not a big deal.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If you are not allowed to access the new window content, then the problem you are encountering is a basic security feature of web browsers. Citing mdn:

The returned reference can be used to access properties and methods of the new window as long as it complies with Same-origin policy security requirements

To read more about Same-origin policy

If your new window respects the Same-origin policy, then you can access the content of the new window with for example:

// Open index.html from the current origin
const newWindow = window.open('index.html')
const h1 = newWindow.document.querySelector('h1')

If you want to avoid asking users for pop-up permission, then you should probably use a link instead of a pop-up.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!