如何将iframe与模糊和焦点一起使用

How to use iframe with blur and focus

本文关键字:焦点 一起 模糊 iframe      更新时间:2023-09-26

我想对iframe进行模糊和聚焦操作,

我的代码场景是,我在网页中写了一个android问题,在这个问题旁边我显示了android手机的图片,问题下面写的代码是什么,输出将显示在该图片中,如果你不在浏览区域,标题将显示为不活动。

动作应该是聚焦或不聚焦。

对于我正在写的这个命令,

<div class="andr_app">
  <iframe src=" <%= request.getContextPath()%>/images/mob_empty.png"       width="400px" height="800px" id="iFrameUrl${questionId}"  class="mobileDisplayIframe" frameborder="0" scrolling="no"></iframe>
 </div>

请帮我一下。

iFrame元素没有焦点或模糊事件,因此需要使用窗口。

var iframe  = document.getElementById('iframe');
var iframeWindow = iframe.contentWindow;
iframeWindow.onfocus = function(){
    //focussed
}
iframeWindow.onblur = function(){
    //blurred
}

参考:答案

我终于得到了答案,但不是在iframe中。我将iframe更改为object,

<object data="<%= request.getContextPath()%>/images/mob_empty.png" width="325px" height="560px" style= "padding-right: 85px"; id="iFrameUrl${questionId}" id="iFrameUrl${questionId}"  class="mobileDisplayIframe" frameborder="0" scrolling="no">
 </object>