T
thinkfr33ly
I have a page that inserts a block of javascript dynamically into the
page "Test.html". The inserted block, "Block A", then does a
document.write of another script block "Block B". This script block
does its own document.write of one last script block "Block C". The way
this occurs is somewhat out of my control, and I need to find a way to
work within this framework. This only needs to work in IE 5.5 or
better.
My problem is that the code in Block C is not evaluated by the
javascript parser. I can get it to evaluate only by doing a "ctrl+n" in
IE which causes IE to open the current document in a new window. This
also happens to cause IE to re-parse the existing DOM's javascript and
thereby finally execute Block C.
I need a way to have Block C inserted and evaluated without having to
do a CTRL+N. There are the following caveats to the modifacations I can
make.
1.) We can insert/modify whatever script we want in test.html. (With
one caveat, see below.)
2.) We have no ability to modify Block A's source.
3.) We have no ability to modify Block B's source, except in that we
can change the contents of its document.write calls.
4.) We can modify whatever we want with Block C. (Since this block is
just what's written by block C. See below.)
The reason for these restrictions is that some of these scripts do not
belong to us. (They belong to a 3rd party server suit and we cannot
modify them.)
The caveat concerning test.html is that whatever is written will be
written *after* the page has been loaded into the browser. In fact, it
will be written by manipulating the DOM with external code. (This stuff
all lives in a client application hosting an IE control.) The insertion
of the javascript occurs once the IE control says that the current
document is completely done loading.
As it is now, the client application is written to insert the
javascript into either an existing javascript tag in the HEAD, or by
creating a new javascript tag. We can change whatever we want as far as
the contents, but not where it is inserted. Also, once the javascript
is inserted, the client app executes a javascript function of our
choice. Now, we can modify the client application if needed, but I
would really rather avoid that if possible.
Below is the contents of Test.html, as well as Block A, Block B, and
Block C. Be sure to modify the SRC paths where needed.
--------------------------------------
START Test.html
--------------------------------------
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript" TYPE="text/JavaScript">
var content = document.createElement("script");
content.src = "http://www.somedomain.com/Block_A.js";
content.id = "blocka";
content.language="javascript";
document.getElementsByTagName("HEAD")[0].appendChild(content);
</SCRIPT>
</HEAD>
<body>
This is a test page.<br /><br />
The first time it loads you will see <b>one dialog</b>.<br />
Hit CTRL+N and you will now see <b>two dialogs</b>.<br />
<br />
Click the following button to view the current page DOM contents.
<input type="submit"
onclick="alert(document.documentElement.outerHTML);return false;"
value="DOM Source" />
</BODY>
</HTML>
--------------------------------------
END Test.html
--------------------------------------
--------------------------------------
START Block_A.js
--------------------------------------
document.write("<SCRI"+"PT LANGUAGE='JavaScript'
SRC='http://www.somedomain.com/Block_B.js'></SCR"+"IPT>");
alert("Block A Written");
page "Test.html". The inserted block, "Block A", then does a
document.write of another script block "Block B". This script block
does its own document.write of one last script block "Block C". The way
this occurs is somewhat out of my control, and I need to find a way to
work within this framework. This only needs to work in IE 5.5 or
better.
My problem is that the code in Block C is not evaluated by the
javascript parser. I can get it to evaluate only by doing a "ctrl+n" in
IE which causes IE to open the current document in a new window. This
also happens to cause IE to re-parse the existing DOM's javascript and
thereby finally execute Block C.
I need a way to have Block C inserted and evaluated without having to
do a CTRL+N. There are the following caveats to the modifacations I can
make.
1.) We can insert/modify whatever script we want in test.html. (With
one caveat, see below.)
2.) We have no ability to modify Block A's source.
3.) We have no ability to modify Block B's source, except in that we
can change the contents of its document.write calls.
4.) We can modify whatever we want with Block C. (Since this block is
just what's written by block C. See below.)
The reason for these restrictions is that some of these scripts do not
belong to us. (They belong to a 3rd party server suit and we cannot
modify them.)
The caveat concerning test.html is that whatever is written will be
written *after* the page has been loaded into the browser. In fact, it
will be written by manipulating the DOM with external code. (This stuff
all lives in a client application hosting an IE control.) The insertion
of the javascript occurs once the IE control says that the current
document is completely done loading.
As it is now, the client application is written to insert the
javascript into either an existing javascript tag in the HEAD, or by
creating a new javascript tag. We can change whatever we want as far as
the contents, but not where it is inserted. Also, once the javascript
is inserted, the client app executes a javascript function of our
choice. Now, we can modify the client application if needed, but I
would really rather avoid that if possible.
Below is the contents of Test.html, as well as Block A, Block B, and
Block C. Be sure to modify the SRC paths where needed.
--------------------------------------
START Test.html
--------------------------------------
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript" TYPE="text/JavaScript">
var content = document.createElement("script");
content.src = "http://www.somedomain.com/Block_A.js";
content.id = "blocka";
content.language="javascript";
document.getElementsByTagName("HEAD")[0].appendChild(content);
</SCRIPT>
</HEAD>
<body>
This is a test page.<br /><br />
The first time it loads you will see <b>one dialog</b>.<br />
Hit CTRL+N and you will now see <b>two dialogs</b>.<br />
<br />
Click the following button to view the current page DOM contents.
<input type="submit"
onclick="alert(document.documentElement.outerHTML);return false;"
value="DOM Source" />
</BODY>
</HTML>
--------------------------------------
END Test.html
--------------------------------------
--------------------------------------
START Block_A.js
--------------------------------------
document.write("<SCRI"+"PT LANGUAGE='JavaScript'
SRC='http://www.somedomain.com/Block_B.js'></SCR"+"IPT>");
alert("Block A Written");