在页面加载时从iframe移除焦点 [英] Remove focus from Iframe on page load
问题描述
我有一个这样嵌入的iframe:
I have an Iframe embedded like this:
<iframe id="foo" src="http://www.something.com" style="width: 90%; height: 300px"></iframe>
每次页面加载焦点都会从页面顶部丢失,并切换到页脚中的此iframe.我想知道如何从中移除焦点并使页面加载正常"?
Each time the page loads focus gets lost from the top of the page and switches to this Iframe that is in the footer.I was wondering how can i remove the focus from this and make the page load "normally"?
谢谢!
更新:是的,iframe是从其他来源(不是同一域)加载的
Update: Yes, iframe is being loaded from another source (not the same domain)
推荐答案
如果假定iframe不是来自同一域,则可以将其他任何可聚焦的dom元素放置在页脚中的iframe之后,并将autofocus
设置为true
.如果不起作用,请在父主窗口中尝试以下操作:
if assumed the iframe is not served from the same domain.. you can place any other focusable dom element after the iframe in the footer with autofocus
set as true
. And if that does not work please try the following in the parent main window:
$(window).on('load', function() {
setTimeout(function(){$("body").focus()}, 100);
};
或者是香草JS
window.onload = function() {
document.getElementById("some-focusable-element-from-parent-window").focus();
};
这篇关于在页面加载时从iframe移除焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!