gpt4 book ai didi

Javascript:将按键事件传递给 iframe

转载 作者:行者123 更新时间:2023-11-30 08:41:14 27 4
gpt4 key购买 nike

我有一个基本的 HTML 设计,里面有一个 IFRAME,如果我想使用箭头/页面向上、向下滚动,首先我必须关注 iframe。相反,我想将按键事件“转发”给它。在:

<script>
document.onkeypress = function(e) {
top.frames['iframe'].document.onkeypress(e);
}
</script>

但这行不通。 我不能使用 jQuery!

最佳答案

HTML5 中有一项新功能“window.postMessage”,它允许 iFrame 和宿主窗口之间进行通信。

Mozilla Developer Center - window.postMessage 上有一些很好的文档页面。

//Syntax
otherWindow.postMessage(message, targetOrigin, [transfer]);

关于Javascript:将按键事件传递给 iframe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26195334/

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