将焦点设置为IE中的iFrame [英] Setting Focus to an iFrame in IE

查看:150
本文介绍了将焦点设置为IE中的iFrame的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中有一个树菜单,点击菜单项,它会在iFrame中加载一个URL。我喜欢将焦点放在iFrame中加载页面的元素中。

There is a tree menu in my application and on click of the menu items, it loads a url in a iFrame. I like to set the focus in an element of the page loaded in the iFrame.

我使用这个代码,而它在所有的浏览器中都能很好地工作除了IE

var myIFrame = $("#iframeName");
myIFrame.focus();
myIFrame.contents().find('#inputName').focus();

我尝试过所有不同的选项,如使用setTimeout,但没有机会。

I have tried all different options like using setTimeout, but no chance.

页面加载后,当我点击Tab键时,它进入第二个输入,这意味着它已经在第一个输入,但它不显示光标!

After the page loads, when I hit the tab key, it goes to the second input, which means it's been on the first input, but it doesn't show the cursor!

我正在使用ExtJS和ManagedIFrame插件。

I am using ExtJS and the ManagedIFrame plugin.

任何帮助都不胜感激。

推荐答案

您需要调用iframe的窗口的 focus()方法对象,而不是iframe元素。我不是jQuery或ExtJS的专家,所以下面的例子不使用。

You need to call the focus() method of the iframe's window object, not the iframe element. I'm no expert in either jQuery or ExtJS, so my example below uses neither.

function focusIframe(iframeEl) {
    if (iframeEl.contentWindow) {
        iframeEl.contentWindow.focus();
    } else if (iframeEl.contentDocument && iframeEl.contentDocument.documentElement) {
        // For old versions of Safari
        iframeEl.contentDocument.documentElement.focus();
    }
}

这篇关于将焦点设置为IE中的iFrame的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆