简体   繁体   中英

loading javascript and communication between iframes

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM