-1

I have a piece of JS code to be executed which contains an unescape function inside document.write method as below.

document.write(unescape('')); 

But, I am not allowed to use document.write method. How to implement this without using document.write ?

Raheeb M
  • 505
  • 2
  • 5
  • 13
  • Call the function, assign its output to a variable and set it using `.innerHTML`. Is that what you want? [Sample](http://jsfiddle.net/hari_shanx/rArgd/) – Harry Oct 19 '13 at 11:26
  • what the.. are you trying to do....?? – Psych Half Oct 19 '13 at 11:27
  • http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem – ThiefMaster Oct 19 '13 at 11:28
  • document.write(unescape('%3Cimg alt="Chat Now" src="' + (('https:' == document.location.protocol) ? 'https:' : 'http:') + '//someurl?0&cbdid=000&wdid=111" border="0" id=' + bccbId + ' /%3E')); This code I need to execute without using document.write. – Raheeb M Oct 19 '13 at 12:01

1 Answers1

1

This is the only way to write directly to the HTML document. But you can always change the content of a container element (for example a DIV, or table CELL) without using document.write, but using for example the innerHTML DOM property of an element:

var el = document.getElementById("content");
el.innerHTML = "<b>An example that modifies the HTML document</b>";

<div id="content"></div>

Using the code above you can write:

el.innerHTML = unescape('...');

An answer to the same question and a link to a DOM manipulation tutorial can be found in this SO post.

Community
  • 1
  • 1
keenthinker
  • 7,645
  • 2
  • 35
  • 45