document.write | Community
Skip to main content
Neha_Thaker
December 8, 2015
Solved

document.write

  • December 8, 2015
  • 1 reply
  • 1967 views

Hi,

We are implementing 3rd Party tags using DTM Event based rules. We are adding this as Non-sequential HTML or Non-sequential Javascript Third Party Tags.

But, the problem we face now is , we get some tags where it has <script> tags and within this script tags there is document.write() statement having a <script> tag to load a Javascript file.

eg :

<script>

var value = somevaluegenerated;

document.write('<script src="xyz.js?para1=one&para2=' + value + '"></script>);

</script>

How ever we found out that DTM does not support document.write() in this scenario.

Can you please let us know what is the option for adding such kind of 3rd Party tags?

Thanks

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by ParitMittal

Hi Neha,

DTM supports document.write(). The only thing which needs to be kept in mind is to change the syntax of <script> tag within the document.write function.  

 The reason why the above piece of your code is not working is that when we are embedding javascript in an HTML page the HTML parser when finds your first script tag will immediately try to find the closing tag. Since your closing script tag is in your document.write you'll find yourself in a pickle.

Hence the piece of code should be modified as :

<script>

var value = somevaluegenerated;

document.write('<script src="xyz.js?para1=one&para2=' + value + '"><\/script>');// This line is modified

</script>

We have also tested a piece of test code on our end and the code is perfectly working.

Thanks & Regards

Parit Mittal

1 reply

ParitMittal
ParitMittalAccepted solution
Level 10
December 10, 2015

Hi Neha,

DTM supports document.write(). The only thing which needs to be kept in mind is to change the syntax of <script> tag within the document.write function.  

 The reason why the above piece of your code is not working is that when we are embedding javascript in an HTML page the HTML parser when finds your first script tag will immediately try to find the closing tag. Since your closing script tag is in your document.write you'll find yourself in a pickle.

Hence the piece of code should be modified as :

<script>

var value = somevaluegenerated;

document.write('<script src="xyz.js?para1=one&para2=' + value + '"><\/script>');// This line is modified

</script>

We have also tested a piece of test code on our end and the code is perfectly working.

Thanks & Regards

Parit Mittal