gpt4 book ai didi

javascript - 从 iframe 中移除焦点?

转载 作者:行者123 更新时间:2023-11-28 07:07:48 25 4
gpt4 key购买 nike

我有这个代码:

<iframe src="/go/afflink.php" width="100%" height="400px" seamless="seamless" scrolling="yes" frameborder="0"></iframe>

显然afflink.php是一个外部网站的附属链接,所以我无权访问它。

iframe 位于我的评论页面的底部。问题是,每当我打开页面时,浏览器都会向下滚动到底部以显示 iframe。我希望浏览器忽略焦点。我该怎么做?

我在 stackoverflow 上进行了搜索,但似乎没有“javascript focus on other element”对我有用。

最佳答案

如果假设 iframe 不是从同一个域提供的..您可以在页脚中的 iframe 之后放置任何其他可聚焦的 dom 元素,并将 autofocus 设置为 true。如果这不起作用,请在父主窗口中尝试以下操作:

$(window).on('load', function() {
setTimeout(function(){$("body").focus()}, 100);
});

或者使用普通 JS

window.onload = function() {
document.getElementById("some-focusable-element-from-parent-window").focus();
};

关于javascript - 从 iframe 中移除焦点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31560234/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com