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 >
<
becomes <
"
becomes "
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
Post a Comment