adworldmedia
asked on
Injecting Javascript Not Working
Because of the way we are loading these pages, we want to use the DOM to inject <SCRIPT> variables and source...
But, for some reason - its not working.
I've also tried:
And I get an error about writing to the page...
I'm not sure if there is anything I can do... I have no access to the fo.js script also, as its being loaded externally from a source we do not own.
Thanks
function putJS(cid, pid) {
var _line1 = '<scr' + 'ipt>var zflag_nid="607"; var zflag_cid="' + cid + '"; var zflag_sid="' + pid + '"; var zflag_width="1"; var zflag_height="1"; var zflag_sz="94";<\/script>';
var _line2 = "<scr" + "ipt src='http://newt1.com/jsc/z5/fo.js'><\/script>";
var _script = document.createElement("div");
_script.innerHTML = _line1 + _line2;
(document.getElementsByTagName("body")[0] || document.documentElement).appendChild(_script);
}
But, for some reason - its not working.
I've also tried:
function putJS(cid, pid) {
var _script = document.createElement("script");
_script.innerHTML = 'var zflag_nid="607"; var zflag_cid="' + cid + '"; var zflag_sid="' + pid + '"; var zflag_width="1"; var zflag_height="1"; var zflag_sz="94";';
//_script.onload = scriptLoaded;
var _scriptSource = document.createElement("script");
_scriptSource.src = "http://www.com/fo.js";
_script.async = true;
_scriptSource.async = true;
var docFrag = document.createDocumentFragment();
docFrag.appendChild(_script);
docFrag.appendChild(_scriptSource);
(document.getElementsByTagName("head")[0] || document.documentElement).appendChild(docFrag);
}
And I get an error about writing to the page...
I'm not sure if there is anything I can do... I have no access to the fo.js script also, as its being loaded externally from a source we do not own.
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window
your -
_script.innerHTML
will fail, , as the document.createElement("sc