简体   繁体   中英

How to use iframe with blur and focus

I want to give action to iframe with blur and focus,

The scenario of my code is,I written a android question in webpage,beside that question I displayed android phone picture,what ever the code written below the question,the output will be shown in that picture and if you are out of browsing area,the title will shown as inactive.

action should be infocus or outfocus.

for this command I am writing,

<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>

Please help me in this.

The iFrame element doesn't have focus or blur events, so you need to use the window.

var iframe  = document.getElementById('iframe');
var iframeWindow = iframe.contentWindow;

iframeWindow.onfocus = function(){
    //focussed
}
iframeWindow.onblur = function(){
    //blurred
}

Reference: answer

Finally I got my answer,but not in iframe. I change iframe to 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> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM