Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
61
rated 0 times [  65] [ 4]  / answers: 1 / hits: 24389  / 11 Years ago, thu, august 29, 2013, 12:00:00

I have a value that I'm currently accessing and passing to a JavaScript function through an onclick.



<a href=# onclick=openTextWindow('<%=myVar.varDefinition.getText()%>');>Text</a>


An example value that I'd receive from the getText method is shown below.



<h1>My Header</h1><br />My text


This value is then passed to my openTextWindow method.



function openTextWindow(inText) {
myWindow = window.open('','','width=500, height=300');
myWindow.document.write(inText);
myWindow.focus();
}


For some reason, the value stored in inText doesn't match the string with HTML tags that I showed above. It ends up looking like this.



<lt/>h1<gt/>My Header<lt/>/h1<gt/><lt/>br /<gt/>My text


When inText is written to myWindow, I want that new window to render with the text My Header within a styled header and My text on a line below that. I've tried replacing and escaping characters with no luck. Any ideas on how to fix this or a better way to accomplish what I'm trying to do? Thanks!


More From » html

 Answers
3

You can stash your HTML in a hidden DIV or textarea, then grab that from your function instead of trying to pass it inline.



<a href=# onclick=openTextWindow('DIV1');>Text</a>
<div id=DIV1 style=display:none><%=myVar.varDefinition.getText()%></div>


JS:



function openTextWindow(divName) {
var inText = document.getElemenyById(divName).innerHTML;
myWindow = window.open('','','width=500, height=300');
myWindow.document.write(inText);
myWindow.focus();
}

[#76028] Wednesday, August 28, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jocelynkarsynr

Total Points: 472
Total Questions: 98
Total Answers: 96

Location: Macau
Member since Mon, Nov 16, 2020
4 Years ago
jocelynkarsynr questions
Tue, Feb 8, 22, 00:00, 2 Years ago
Sat, Jul 11, 20, 00:00, 4 Years ago
Sun, May 10, 20, 00:00, 4 Years ago
Sat, Jan 18, 20, 00:00, 4 Years ago
;