Avoid multiple jQueries & Boostrap in iFrame

I have an iFrame where an embedded site uses jQuery plus Bootstrap and my parent site uses those as well. Can I delete them on the remote site and rely on the parent website?



source to share

2 answers

For some of the bootstrap scripts, you can avoid this by using the sandbox iframe attribute.

<iframe id="myIframe" sandbox="allow-forms allow-pointer-lock allow-popups allow-same-origin allow-top-navigation">


I don't have a solution for the css part yet.

Otherwise, load the content with ajax and then render it, moving the loaded content to the desired location (jquery helps to do this). It doesn't have to load any resource, therefore.



if (window.parent.jQuery) {
    delete window.jQuery;
    delete window.$;
    jQuery = window.parent.jQuery;
    $ = jQuery;


You can do this in an iframe. But be careful with the selector, the default context will be the document of the parent window.



All Articles