javascript - 动态使用 iframe 作为页面覆盖

标签 javascript jquery html css iframe

我已将以下 iframe 添加到页面

<iframe src='http://redbug.redrocksoftware.com.au:80/Pages/chamara.html' style="position:absolute;z-index:1;" ></iframe>

chamara.html 页面包含一个按钮,当我单击该按钮时,我需要用覆盖层覆盖当前页面。

反馈是iframe内的按钮: enter image description here

当我点击它时,我需要发生如下所示的事情。

enter image description here

我尝试过 iframe 绝对定位和 z-index,但还没有任何效果。

最佳答案

哈哈,终于完成demo了! :P

好吧,我们走吧。如果您需要 iframe 仅在按钮被触发时覆盖整个页面,您可以使用 jQuery 来处理单击事件。您需要使用 contents() 获取 iframe 内容,然后使用 find() 获取所需的元素。基本上是这样的:

$("#iframe").contents().find("#iframe_button").click(function () {
    // Button fired!
})

为了iframe覆盖所有页面,我写了这个CSS类:

.iframe_cover {
    position:absolute; 
    top:0; 
    left:0; 
    width:100% !important; 
    height:100% !important;
    border:0;
}

因此,当按钮被触发时,iframe 将具有此类。看:

$("#iframe").contents().find("#iframe_button").click(function () {
    $("#iframe").addClass("iframe_cover");
})

演示:http://rafaelalmeida.net78.net/exemplos/soen/29454285-iframe-button/

关于javascript - 动态使用 iframe 作为页面覆盖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29454285/

相关文章:

javascript - AngularJS 条件 ng-disabled 不重新启用

javascript - 滑动 slider ...删除箭头

php - 使用正则表达式从 <a> HTML 标记获取所有属性

javascript - jQuery 单击功能可从元素中删除属性并在单独单击时恢复属性

javascript - Vuejs 组件等待 facebook sdk 加载

javascript - javascript 中 IIFE 的 'this' 关键字

javascript - 为 parent 的 parent 添加类(class)

javascript - jQCloud - 如何清除它?

javascript - -webkit-backface-visibility 导致内存泄漏?

javascript - 用按钮显示隐藏元素