472,345 Members | 1,511 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,345 software developers and data experts.

write to a window.open()

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
Feb 17 '06 #1
1 2803
Angelos wrote:
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');
}
//-->


First off, you don't need the <-- and //--> - take them out.

Now, as to the specific problem you're having:

You can address the new window as a variable - so where you have
pre_window = window.open('test_preview.php', 'PREVIEW');
you can now address that window as pre_window. For example:
pre_window.document.write(content);

There are, I think, better ways to handle writing the content (using
DOM), but that should at least get you a start.

Feb 17 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: James Marshall | last post by:
I'm writing a library where I want to override document.write(), but for all document objects; thus, I want to put it in the prototype. I tried ...
1
by: Nat | last post by:
Hi I have following code: ----------------- protected override void Render(HtmlTextWriter w) { if (helpString!=null) { w.Write("<span...
2
by: Jenny | last post by:
In the code below, I can write html content var t='<body BGCOLOR=blue>' for a new window. But if it contains javascript, such as var t='<body...
7
by: Remi Bastide | last post by:
I'm trying to open a blank window and write a message in it. The following page works as expected in IE, but in Firefox the message is not written:...
2
by: Adam | last post by:
This is frustrating me. Opening IE displays the following code fine. When I open a new window the code no longer works. All the HTML is overwritten...
4
by: Nat | last post by:
Help, I have following code: ----------------------------------------------------- protected override void Render(HtmlTextWriter w) { if...
11
by: Josh | last post by:
Hi, Anyone know how to open a New Browser window and then "response.write" to the new window. I know how to open a new window, but then...
2
by: Steve | last post by:
I want to open a window that has been pre-formatted with a table and then write rows to the table. The pre-formatted url is named budget.html and...
8
by: Mateusz Viste | last post by:
Hi, I am trying make some multimedia files playable from my website. So far, I am able to generate dynamically a new page containing the right...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.