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

161
Views
Post message to cross-origin iframe in JavaScript

I'm new to JavaScript, and I'm trying to post a message to my iframe in order to scroll it. I'm trying to achieve it using this code.

scroll(i) {
  var src = $("#iframe").attr("src");
  $("#iframe").contentWindow.postMessage(i, src);
}

This code is working when launched in Chrome console, but it is not working when launched from the Webapp (using a button).

I get an error saying contentWindow is undefined. Does someone know why?

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

0

$(document).ready(function(){
  $(window).scroll(function() {
   scroll("yourHtmlFile.html");
  });    
 function scroll(i){
    $("#iframe").attr("src",i);
 }});
about 4 years ago · Juan Pablo Isaza Report

0

For some reason it seems my code was managing $("#iframe") as an array. I got this issue solved by doing this:

scroll(i) {
  var src = $("#iframe")[0].attr("src");
  $("#iframe")[0].contentWindow.postMessage(i, src);
}
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!