使用Javascript / jQuery将焦点设置为嵌入式Flash影片/ HTML嵌入元素
有没有办法使用JavaScript将焦点设置为嵌入HTML元素? 测试用例:在页面上嵌入YouTubevideo。
我无法控制嵌入式Flash元素。 那么,有没有办法只使用JavaScript来关注它?
我在某地读过,调用element.focus()方法仅适用于IE。 我需要一种独立于浏览器的方式,适用于Chrome / Firefox。
谢谢!
这仅适用于Internet Explorer。
我也尝试过这样做,最后使用jquery找到了一个很好的解决方案:
var gotoflash = jQuery(“#flash_file”)。offset()。top; jQuery(“html:not(:animated),body:not(:animated)”)。animate({scrollTop:gotoflash},1000);
其中:< div id =“flash_file”> flash对象代码< / div>
可以通过动态添加Flash内容来完成,例如使用swfobject 。
我还没有证实这一点,但你可以试试:
function thisMovie(movieName) { if (navigator.appName.indexOf("Microsoft") != -1) { return window[movieName]; } else { return document[movieName]; } } // Call from within another function: thisMovie("FlashObjectID").focus(); thisMovie("FlashObjectID").showFlash(); // showFlash() is an AS3 ExternalInterface call from JS to .swf which establishes the TextInput.setFocus(); method
来源: http : //www.htmlforums.com/archive/index.php/t-64150.html