[SOLVED] Document.write in ionic


#1

When I use document.write(‘Hello’) in a div, whole page will change to ‘Hello’ .


Example:
When execute the code :< div >document.write(‘Hello’)< /div >
Expect Result:
< div >Hello< /div >

Result:
Hello


  1. How can I use document.write() in ionic?
  2. Is there any alternative?
  3. Is there any plan to fix this problem, ionic ?

#2

why do you need document.write??? what do you want to do?


#3

I want to implement our website in ionic for mobile.
I want to get our notes data from our db and display in divs.
Our notes is written by pure js and html and it contain many document.write(), but the notes is written by many people.
Is there any solution to replace document.write()?


#4

I have been solve my problem via the tested sample code pasted at the below:

function replace_document_dot_write(replace_content){ var s_regex=/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi; var uid=0; replace_content=replace_content.replace(s_regex,function(match_str){ var dw_regex=/document\.write\((.*?)\)/g; var new_d=new Date(); var dw_id ="DocumentDotWriteID_"+new_d.getTime()+"_"+(uid++); var new_match_str=match_str.replace(dw_regex,"DocumentDotWrite('"+dw_id+"',$1)"); return new_match_str.replace('<script type="text/javascript">','<span id="'+dw_id+'" class="dw_span"></span><script type="text/javascript">'); }); return replace_content; } function DocumentDotWrite(dw_id,writetxt){ var dw_node=document.getElementById(dw_id); dw_node.innerHTML+=writetxt; };

I hope these code may help others who is facing on same problem !!!