|  | document.write call position |  | |
| | | Guest |  |
| Posted: Tue Sep 16, 2008 7:12 am Post subject: document.write call position |  |
Hello,
I am trying to override document.write, because there are cases in which a slow response from a <script src=...> request which produces document.write calls is received after the page has finished loading. In that case, it overwrites the entire page (as document.write does when the page parsing is over).
I am trying to use Resig's htmlparser for this mission (http:// ejohn.org/blog/pure-javascript-html-parser/), doing HTMLtoDOM instead of the write. However, I need to inject the new DOM object in the correct position in the tree, and that's where the document.write was called.
Is there a way to tell where in the DOM the document.write is located when it's called? I need to know this in the scope of the overriding:
<code> document.write = function(text) { HTMLtoDOM(text,callPosition); }; </code>
How do I figure out callPosition?
Oren |
| |
| | | Thomas 'PointedEars' Lahn |  |
| Posted: Tue Sep 16, 2008 12:12 pm Post subject: Re: document.write call position |  |
| |  | |
orensol@gmail.com wrote:
| Quote: | I am trying to override document.write, because there are cases in which a slow response from a <script src=...> request which produces document.write calls is received after the page has finished loading. In that case, it overwrites the entire page (as document.write does when the page parsing is over).
|
Chances are that you have not properly analyzed the problem, and therefore you jumped to conclusions as to its cause(s).
| Quote: | I am trying to use Resig's htmlparser for this mission (http:// ejohn.org/blog/pure-javascript-html-parser/), doing HTMLtoDOM instead of the write.
|
Bad Idea, given Resig's lack of experience in this field. (And that's a polite way of putting it.)
| Quote: | However, I need to inject the new DOM object in the correct position in the tree, and that's where the document.write was called.
Is there a way to tell where in the DOM the document.write is located when it's called?
|
Since the `script' element that is required to include the statement has to be parsed first, the new element(s) would be inserted in the DOM tree after that `script' element. That is what can be observed with Firebug in Firefox.
| Quote: | I need to know this in the scope of the overriding:
code
|
This is not a bulletin board, such confusing pseudo-tags are unwished for.
| Quote: | document.write = function(text) { HTMLtoDOM(text,callPosition); }; /code
|
An even worse idea, attempting to overwrite host object's methods that are more likely to be read-only.
| Quote: | How do I figure out callPosition?
|
Wrong question, and you can't, there.
If document.write() does not work for you (which I doubt), use DOM creator and mutator methods to insert elements into the tree instead. Use DOM retrieval methods to get the necessary context references.
PointedEars -- Prototype.js was written by people who don't know javascript for people who don't know javascript. People who don't know javascript are not the best source of advice on designing systems that use javascript. -- Richard Cornford, cljs, <f806at$ail$1$8300dec7@news.demon.co.uk> |
| |
|
|