在子框架上使用jquery而不需要再次加载它(using jquery on child frame without loading it again)

编程入门 行业动态 更新时间:2024-10-27 22:20:14
在子框架上使用jquery而不需要再次加载它(using jquery on child frame without loading it again)

是否有可能加载和使用jquery在父iframe页面和内部iframe没有加载jquery两次,这意味着在页面中加载jquery一次,并在内部的ifrmae中使用它。

is it possible to load and use jquery in the parent iframe page & inside the iframe whithout loading jquery twice, meaning to load jquery just once in the page and using it in the ifrmae within.

最满意答案

当然,只要确保<iframe>不加载jQuery脚本,即<script src="....">那么您可以在父级访问jQuery实例,如下所示:

var $ = window.top.$;

确保使用第二个参数使用正确的上下文:

$('img', document);

如果这是不可能的,你不能“阻止”脚本被下载和执行。

Sure, just make sure the <iframe> isn't loading the jQuery script i.e. <script src="...."> then you can access the jQuery instance in the parent like so:

var $ = window.top.$;

Be sure to use the correct context using the second parameter:

$('img', document);

If this isn't possible you can't "prevent" a script from being downloaded and executed.

更多推荐

jquery,iframe,使用,load,电脑培训,计算机培训,IT培训"/> <meta name="descrip

本文发布于:2023-04-29 10:49:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1336252.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:而不   框架   加载   jquery   loading

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!