The problem can be Iframe loading before the script is executed. This can be prevented by adding the Iframe using Javascript.


Code:
var iframe = document.createElement("iframe");
document.body.appendChild(iframe);