0

I'am trying to set focus to a document. The javascript/jQuery function is placed into an document which is opend inside a frame (There are 5 other frames on the website).

Heres a little code snipped from my current state:

$(document).ready(function () {
    $(window).focus();
    $(document).keypress(function (e) {
    [...]
    });
});

This works well in Chrome and IE11 but not in Firefox 25 (Should be related to window.focus(), self.focus() not working in firefox).

I tried around with $(document).focus() but this doesn't work at all (focus isn't set to the document/keypress event doesn't raise). Now I wanted to try to set focus to document when all frames are fully loaded (In the case that focus is also set in another frame which is loaded later). So I came up with something like:

//Get the root window, attach event which is raised when all content(frames) are loaded.
$(window.opener).load(function () {
    $(document).focus();
});

But the load event is never raised. Does anyone have an idea why this event is never raised? Or any other ideas how to set the focus on the document inside a frame (I can't add anything new to parent files, this would influence other projects)?

Community
  • 1
  • 1
cb_dev
  • 379
  • 1
  • 3
  • 16

1 Answers1

-1
  function setFocusThickboxIframe() {
  var iframe = $("#TB_iframeContent")[0];
  iframe.contentWindow.focus();

}

$(document).ready(function(){
 $("#id_cmd_open").click(function(){
       setTimeout(setFocusThickboxIframe, 100);
  return false;
 });
Sandy
  • 817
  • 2
  • 11
  • 18