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

143
Views
How to get reference to the iframe from which script html tag was generated?

I have small snippet that is inside iframe and generates script html tag and appends it to the window.top.document.head.

Now I want to know how do I check from within potato.js from which iframe it was generated from once it is already loaded?

<!DOCTYPE html>
    <html lang="en">
    <head>
    </head>
    <body>
        <iframe>
            <!DOCTYPE html>
            <html>
            <head>
                
            </head>
            <body>
                <script>
                    (function() {
                        var s = document.createElement('script');
                        s.setAttribute('type','text/javascript');
                        s.setAttribute('src','https://test.com/potato.js');
                        window.top.document.head.appendChild(s);
                    })();
                </script>
            </body>
            </html>
        </iframe>
    </body>
    </html>

Edit: I can not change this code inside the iframe

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

0

That information isn't stored automatically.

The only way I can think of would be to add an expando-prop to the script with a reference to the current window (i.e. the frame's window)…

s.sourceWindow = window;

… then read that from within potato.js …

const sourceWindow = document.currentScript.sourceWindow;

… and then loop over all the frames (window.frames) looking for a match.

Since you are using window.top and not window.parent you might need to be recursive there.

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!