3

I know Some programs (like grease monkey) can modify DOM just after the DOM is loaded completely.

But Is it possible during the DOM is loading? or before loaded?

kwangbul
  • 41
  • 1
  • 4

2 Answers2

2

Maybe already answered here :

Chrome Extension : Modify DOM before loading
Is it ok to manipulate dom before ready state?
Possible to modify DOM during/before initial DOM parsing?

Community
  • 1
  • 1
Jean-Michel Garcia
  • 2,359
  • 2
  • 23
  • 44
1

Yes, it's possible.

Check out this example:

<div id="t">Some text</div>
<script>
    document.getElementById('t').textContent = "Other text";
</script>
<div>Yay!</div>

The script part will modify the DOM even though the "Yay!" div hasn't loaded. It can only do that because the <div id="t"> is already loaded, though.

This is the extent of how much you can do.

If you want to insert something while the DOM is loading, you can use document.write (this is the trick that most ads providers use to add the script tag wherever their snippet is added).

Florian Margaine
  • 58,730
  • 15
  • 91
  • 116
  • Thanks Margaine. yes.. above example works. But, Can something insert code(above script) during the DOM is loading? – kwangbul Jun 22 '12 at 07:25
  • I mean.. can any OTHER PROGRAMS change browser DOM during A BROWSER DOM is loading – kwangbul Jun 22 '12 at 07:35
  • @kwangbul oh, then look at Jean-Michel Garcia's first link, it's exactly what you want (http://stackoverflow.com/questions/9778637/chrome-extension-modify-dom-before-loading). – Florian Margaine Jun 22 '12 at 07:36