加载 javascript 和 iframe 之间的通信
我开发了一些在页面上呈现 iframe 的 javascript 代码。在框架内部,它加载了用于社交网络的各种 API,例如 facebook、twitter、linked in 等。它基本上是网站的一个工具,允许用户使用其社交网络登录。我还创建了一个简单的 jQuery 插件,可以将此 iframe 加载到模式弹出窗口中。
问题是这样的: 主 iframe 已加载到网站上,但开发人员还希望在同一页面上使用 jquery 插件。它工作正常,但是所有的 javascript 都被加载了第二次。所以基本上这是一种巨大的资源浪费,因为每个社交网络 api 都会被加载两次。我想知道是否有一种方法可以跟踪 api 已经加载,并停止再次加载它们。 2 个 iframe 完全相同。
我尝试向 window.top 添加一些属性,但是由于跨域限制,这不起作用。两个 iframe 属于同一域,但主站点是不同的域。
我还想知道 iframe 是否可以检测主窗口是否已加载 jquery,因为即使不需要,也会再次加载 jquery。
任何意见和建议将不胜感激, 谢谢!
I've developed some javascript code that renders an iframe on the page. Inside the frame, it loads various API's for social networking, such as facebook, twitter, linked in, etc. It's basically a tool for the website to allow users to sign in with their social network. I've also created a simple jQuery plugin that loads this iframe into a modal popup.
Here's the problem:
The main iframe is loaded on the site, but the developer also wants to use the jquery plugin on the same page. It works fine, but ALL of the javascript is being loaded a 2nd time. So basically it is a huge waste of resources, as every social networking api is being loaded twice. I was wondering if there was a way to track that the api's have already been loaded, and to stop loading them again. The 2 iframes are exactly identical.
I tried adding some properties to window.top, but this doesn't work because of cross domain limitations. The two iframes are of the same domain, but the main site is a different domain.
I was also wondering if an iframe can detect if the main window has loaded jquery, as that is being loaded again even when it's not necessary.
Any advice and suggestion would be appreciated,
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不应该为此使用 iframe。听起来您正在创建一个“登录弹出窗口”供用户登录,假设他们单击“评论”并且尚未登录。只需使用一个 div,并将其绝对浮动在页面其余部分之上。
You should not use an iframe for this. It sounds like you are creating a 'login pop-up' for users to login, say if they clicked 'comment' and were not already logged in. Just use a div, and float it absolutely above the rest of page.