java - How can I put a string containing html text to be displayed in a javascript function? -


how can put string containing html text displayed in javascript function?

string test = "displaynext(\"string containing html tags\")";  string nextlink = "<br><a href='#' onclick="+test+"> next</a>"; 

javascript function:

function displaynext(next){     alert(next); } 

i want pass html tags javscript function , display using alert box..how do ??

you'll need encode html tags.

> becomes &gt;
< becomes &lt;
" becomes &quot;

you'll need encode javascript.

' becomes \'

then use single quotes quote javascript (so double quotes don't close onclick attribute prematurely):

string test = "displaynext('" + encodedhtml + "')"; string nextlink = "<br /><a href="#" onclick=\"" + test + "\"> next</a>"; 

Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -