如何抑制javascript异常?

发布于 2024-09-25 23:55:26 字数 201 浏览 0 评论 0原文

在我的应用程序中,我获取了其他一些域页面的内容。它与内容一起运行与特定页面关联的 JavaScript。在 javascript 代码中,编写了“document.selection.createRange()”,该代码在 IE 中运行时抛出异常(因为在 IE 中,出于安全考虑,您无法更改 iframe 的数据,反之亦然)。

所以我的问题是如何抑制异常。 提前致谢 :)

In my application i am getting the content of some other domain's page. Along with the content it is running the javascript associated with the particular page. In the javascript code "document.selection.createRange()" is written which is throwing exception at run time in IE (since in IE due to security concern you can't change iframe's data or the reverse).

So my question is how to suppress the exception.
Thanks in advance :)

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

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

发布评论

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

评论(1

弱骨蛰伏 2024-10-02 23:55:26

您可以在 jQuery 中通过使用带有页面片段的 load 来执行此操作。

如果调用 .load() 时将选择器表达式附加到 URL,
然而,在更新 DOM 之前脚本会被删除,
因此不会被执行

请注意,只有当其他域允许您的域通过 CORS http 标头。

You can do this in jQuery by using a load with a page fragment.

If .load() is called with a selector expression appended to the URL,
however, the scripts are stripped out prior to the DOM being updated,
and thus are not executed

Be aware though that this will only work if the other domain allows your domain access via CORS http headers.

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