Wednesday, June 3, 2009

Set focus on control inside iFrame (jQuery)

//get the IFRAME element - note no hashes in the name, we're using browser functionality 
var iframeRef = document.getElementById("IFRAMEID"); 
//focus the IFRAME element 
$(iframeRef).focus(); 
//use JQuery to find the control in the IFRAME and set focus 
$(iframeRef).contents().find("#CONTROLID").focus();
 
Source

2 comments:

  1. It worked, thanks! :)

    Vipul Limbachiya (http://vipullimbachiya.com)

    ReplyDelete
  2. var iframeRef = document.getElementById("IFRAMEID");

    I don't know what makes this line different from $("#IFRAMEID")... but it does the trick... thanks...

    ReplyDelete