2

I want to insert a div tag with google tag manager, but I get a weird result. This is the situation:

Tested Browser: Chrome (but this failure was validated from external party too)

The google tag manager code

<div>my content</div>
<script>
  document.write("<div>conetnt in the middle</div>");
</script>
<div>another content</div>

The unexpected result (copied from DOM)

<div>my content
  <script>document.write("\x3cdiv\x3econetnt in the middle\x3c/div\x3e");</script>
  <div>conetnt in the middle
    <div>another content</div>
  </div>
</div>

Anyone has any idea, why this happens?

alexwenzel
  • 1,929
  • 2
  • 12
  • 17
  • 1
    http://stackoverflow.com/questions/802854/why-is-document-write-considered-a-bad-practice – isherwood Jul 16 '15 at 14:48
  • try `document.close();` also after write – manoj Jul 16 '15 at 14:52
  • 1
    @blex you tried this inside the google tag manager? because this snippet works fine outside – alexwenzel Jul 16 '15 at 15:20
  • @manoj I tried this, but still the same. – alexwenzel Jul 16 '15 at 15:25
  • Actually I get the exact same result (minus the escaped special chars) when I run this in a standalone html page. The difference is that when I tested it with GTM it was wrapped into a div with display=none, so it was not obvious that this had run as intended. Maybe GTM wants to protect users from messing up their own page (GTM scripts are not supposed to change the layout). – Eike Pierstorff Jul 17 '15 at 18:50

0 Answers0