开发者

Setting focus to an embedded Flash movie/HTML embed element using Javascript/jQuery

开发者 https://www.devze.com 2022-12-15 01:03 出处:网络
Is there a way to set focus to the embed HTML element using JavaScript? Test case: embedded YouTube videos on a page.

Is there a way to set focus to the embed HTML element using JavaScript? Test case: embedded YouTube videos on a page.

I have no control over the embedded Flash element. So, is there a way to set focus on it by using only JavaScript?

I read somewhere that calling the element.focus() method works on开发者_StackOverflow社区ly in IE. I need a browser-independent way that works in Chrome/Firefox.

Thanks!


This only works in Internet Explorer.

http://kb2.adobe.com/cps/155/tn_15586.html


I've tried to do this too, and ended up to a nice solution using jquery:

var gotoflash=jQuery("#flash_file").offset().top;jQuery("html:not(:animated),body:not(:animated)").animate({ scrollTop: gotoflash}, 1000);

where: <div id="flash_file"> flash object code here </div>


It can be done by adding flash content dynamically, for example with swfobject.


I haven't confirmed this, but you could try:

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

source: http://www.htmlforums.com/archive/index.php/t-64150.html

0

精彩评论

暂无评论...
验证码 换一张
取 消