开发者

jquery js import to iframe

开发者 https://www.devze.com 2022-12-13 00:36 出处:网络
I have a page that uses jquery ui\'s tabs. Each tab content is开发者_开发知识库 an iframe with a local page in it. These local pages have been importing their own jquery.js when their parent also have

I have a page that uses jquery ui's tabs. Each tab content is开发者_开发知识库 an iframe with a local page in it. These local pages have been importing their own jquery.js when their parent also have jquery.js imported.

Is there any way i can use the parents jquery inside the iframes, so I dont have to add jquery.js to every single page inside the iframe?

I know parent.$ may work, but I dont want to call parent on every function. Can i instantiate the jquery object from the parent?


Put this on the Iframe and you are done...

var $ = function() {
   var args = [arguments[0], document];
   return parent.$.apply(null, args);
};


Try var $ = parent.$, or something along those lines, at the beginning of your javascript.

0

精彩评论

暂无评论...
验证码 换一张
取 消