如何维护跨域“iframe”的外部拖动事件?

发布于 2024-12-20 18:49:52 字数 904 浏览 3 评论 0原文

我开发了一个用于 360° 图像投影的 jQuery 插件,其中主要的交互方式是鼠标/触摸拖动。当图像位于 iframe 内时,现在的社区面临问题,在拖动图像时,鼠标指针相对容易滑出 iframe“框架”,因此停止帧锁定的“mousemove”“mouseup”事件。 DOM 事件根本不会跨帧冒泡。经常出现的令人不快的结果是卡住拖动(在 jsFiddleiframe-powered UI 将是最好的例子)。

要绕过它,使用 $.unique( $(window).add(window.top) ) 我绑定到 [ window ][ window, window.top] 视情况而定。而且效果很好。如果都在同一个域上。

如果域不同,同源策略将加强并防止绑定到包含页面导致安全错误最终剧本全部失败。

因此,假设上述情况,我的问题是:有没有办法从iframe跨域监听外部拖动事件?

失败的尝试:

  • window.top。 onmousemove =...
  • window.top.addEventListener("mousemove"...
  • $( window.top ).bind("mousemove"...

I develop a jQuery plugin for projection of 360° images, where the main means of interaction are mouse / touch dragging. The now community faces problems when images are inside an iframe, where it is relatively easy for the mouse pointer to slip out of the iframe "frame" while dragging the image, thus ceasing the frame-locked "mousemove" and "mouseup" events. DOM events simply don't to bubble up across frames. Frequent unpleasant result is a stuck dragging (running inside jsFiddle's iframe-powered UI would be the best example).

To route around it, using $.unique( $(window).add(window.top) ) I bind to either [ window ] or [ window, window.top ] depending on the situation. And it works very well. If all on a same domain.

If the domains differ, Same Origin Policy will step up and prevent binding to the containing page causing security errors eventually failing the script all together.

So assuming the above, my question is: is there a way to listen to outside dragging events from an iframe cross-domain?

Failed attempts:

  • window.top.onmousemove =...
  • window.top.addEventListener("mousemove"...
  • $( window.top ).bind("mousemove"...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

请止步禁区 2024-12-27 18:49:52

如果您不是让最终用户嵌入 iframe,而是让他们包含一个 js 脚本文件,然后您可以从中编写 iframe,并与 iframe 事件并行地管理父文档领域中的事件。然后,您可以通过服务器会话将内容传递回 iframe(即动态地将脚本添加到当前页面,修改用户会话,从 iframe 内轮询更改)。这是一个完全不理想的情况......但它会让事情正常工作,并让您访问父环境。多次嵌入会变得混乱,但我认为这对于专家来说是额外的。

If instead of getting the end user to embed an iframe, you can get them to include a js script file, that you can then write the iframe from, and manage events in the realm of the parent document, in parallel to your iframe events. You can then potentially pass things back to the iframe via the server session (ie dynamically add in scripts to the current page which modify the users session, the changes being polled from within the iframe). Thats a completely not ideal situation... but it will get things to work, and gives you access to the parent environment. It gets messy over multiple embeds, but thats extra for experts i think.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文