程序员的知识教程库

网站首页 > 教程分享 正文

调用iframe中的方法/值(iframe用法和代码)

henian88 2024-10-10 05:50:08 教程分享 3 ℃ 0 评论

原文:https://blog.csdn.net/qq_41176306/article/details/119209585

当页面中有iframe时,想在主页面调用iframe中的方法,可以用contentWindow属性。但具体用时还有一点要注意,就是必须等页面加载完成才可以,否则会报错找不到函数。

setTimeout (f,0)的作用很简单,就是为了把f放到运行队列的最后去执行。 就是说,无论setTimeout (f,0)写在哪,都可以保证在队列的最后执行,因为它是异步操作

$(document).off('change', '#timemark').
on('change', '#timemark', function (event) {
  console.log('打印参数time');
  if($(this).is(':checked')){ 
    console.log('iframeWindow的方法');
    setTimeout(function(){
      const iframeWindow=document.getElementById("task-content-iframe");
      iframeWindow.contentWindow.window.currentTime();
      //iframe需加载完,才可调用iframe 中的currentTime()方法
      //获取iframe中元素的值
//iframeWindow.contentWindow.document.getElementById("currentTime").value
    },0)
  }else{ 
    $('#currentVideoTime').val('0:0:1')
  }

});

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表