javascript - Trigger click on iframe -


i'm aware of same-origin policy... getting out of way.

anyway, have slideshow (slide.js) has embedded videos in it. when user clicks video, want slideshow pause. events inside iframe not trigger, i'm trying work around that. right have partial solution. detect blur event on window , if newly focused element iframe pause slideshow:

$(window).blur(function(event){     console.log(event.target);     if($('iframe').is(':focus')){         //clicked inside iframe         console.log('test');     }     console.log('document.activeelement is:');     console.log(document.activeelement);     console.log('\n'); }); 

after loading page in console:

document.activeelement is: body 

now part confuses me. click event fires iframe focus event when click somewhere other iframe first. is, after loading page, if directly click iframe, console not log test. if click either outside frame, or tab in browser, or anywhere else, blur event trigger. after if click iframe, test in console:

after loading page, click different tab go original tab:

window {top: window, window: window, location: location, external: object, chrome: object…} document.activeelement is:  <body class="full">...</body> 

then click iframe:

window {top: window, window: window, location: location, external: object, chrome: object…} test document.activeelement is:  <iframe>...</iframe> 

why???

i put before everything, , didn't help:

$(window).focus(); 

however, works if this:

$('input').focus(); 

if input focused, can click iframe , trigger event without having click else beforehand.

help me, you're hope...

edit:

actually, using native window.focus() seems work me :

fiddle


how appending element set focus :

$('<input>', {type: 'text',                style: 'top: -10000px; position: absolute',                autofocus:true}     ).appendto('body')      .focus(); // make sure 

fiddle

if can, add input element autofocus directly markup, way blur event triggered on first click.

fiddle


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -