Hello there,
I am very new to Javascript and before I explain what I want I'll tell
you in a few words that I am trying to make a button on a WYSIWYG text
editor (RichArea) that previews on a template the content of the editor
and not in just an empty page.
I can't get around the folowing:
I have a page with a form and a text area. In the textarea I write html
code or any text.
Then I hit a button and I open a new window which is a template of a
page and I want to put the content of the textarea from the previous
page inside a content div.
This is the code of the source page:
/********************STARTOF CODE *********************/
<script type="text/JavaScript">
<!--
//dont need to restore borders in change_mode - works faster
function get_content(editor) {
if (!editor)
return '';
var text_area_content;
eval('var text_area = document.getElementById(editor);');
text_area_content = text_area.value;
return text_area_content;
}
function open_window() {
content = get_content('Contentbody');
pre_window = window.open('test_preview.php', 'PREVIEW');
}
//-->
</script>
</head>
<body>
<form action="<? $_SERVER['PHP_SELF'] ?>" name="add_content" method="post">
<textarea name="Contentbody" id="Contentbody" cols="80" rows="10"
wrap="virtual"></textarea>
<br />
<input type="button" name="submit" value="PREVIEW"
onclick="open_window()"/>
</form>
</body>
/********************END OF CODE *********************/
And this is the code for the preview page:
/********************START OF CODE *********************/
<table id="container" border="0" cellpadding="0" cellspacing="0">
<tr><td colspan="2"><div id="header">HEADER</div></td></tr>
<tr valign="top">
<td id="leftDIV">MENU</td>
<td id="content">
<script type="text/JavaScript">
<!--
var text_area = window.opener.document.add_content.Contentbody.val ue;
document.write(text_area);
//-->
</script>
</td>
</tr>
<tr><td colspan="2"><div id="footer">FOOTER</div></td></tr>
</table>
/********************END OF CODE *********************/
That script will do the job... but that's not an option for me because
the form name and textarea name will be Dynamic so
"window.opener.document. add_content.Contentbody. value;"
is not possible.
What I want to do is something like that in the first page:
content = get_content('Contentbody');
pre_window = window.open('test_preview.php', 'PREVIEW');
pre_window.document.write(content);
pre_window.document.close();
but document.write will delete everything when is called... so thats not
an option as well...
My next thought is:
content = get_content('Contentbody');
pre_window = window.open('test_preview.php', 'PREVIEW');
var div = pre_window.document.getElementById("content");
var text = pre_window.document.createTextNode("my text");
pre_window.document.div.appendChild(text);
pre_window.document.getElementById("content").inne rHTML=content;
But that doesn't work... If that works I think that will solve my
problemmm...
By the way the above code was inspired by a reply on a previous post
"document.write() in the middle of a document?"
Any IDeas ?
Thanks a lot
Angelos