Insert JS / JavaScript code into iframe from parent

Viewed 7131

I have a script which I loaded into my parent HTML head from my server... I want to insert that script into my iframe whenever it reloads.

I have a function that makes my iframe reload before it insert scripts into head like this:-

function insertScriptIntoHead(){
    var head = iframe.contentWindow.document.getElementsByTagName('head')[0];
    var script = iframe.contentWindow.document.createElement('script');
    script.src = getFromParent();
    script.type = 'text/javascript';
    head.appendChild(script);
}

This file is of 1.5 mb and upon every reload it is loaded again which I want to eliminate.

I thought if I can load it from parent and put the file on every reload into the iframe then probably I will eliminate the file getting loaded from the server which will save time.

Any help will be appreciated

-Thanks

1 Answers
Related