473,561 Members | 3,730 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(edi tor) {
if (!editor)
return '';
var text_area_conte nt;
eval('var text_area = document.getEle mentById(editor );');
text_area_conte nt = text_area.value ;
return text_area_conte nt;
}
function open_window() {
content = get_content('Co ntentbody');
pre_window = window.open('te st_preview.php' , 'PREVIEW');
}
//-->
</script>
</head>
<body>
<form action="<? $_SERVER['PHP_SELF'] ?>" name="add_conte nt" method="post">
<textarea name="Contentbo dy" id="Contentbody " cols="80" rows="10"
wrap="virtual"> </textarea>
<br />
<input type="button" name="submit" value="PREVIEW"
onclick="open_w indow()"/>
</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"><di v id="header">HEA DER</div></td></tr>
<tr valign="top">
<td id="leftDIV">ME NU</td>
<td id="content">
<script type="text/JavaScript">
<!--
var text_area = window.opener.d ocument.add_con tent.Contentbod y.value;
document.write( text_area);
//-->
</script>
</td>
</tr>
<tr><td colspan="2"><di v id="footer">FOO TER</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.Con tentbody. value;"
is not possible.

What I want to do is something like that in the first page:
content = get_content('Co ntentbody');
pre_window = window.open('te st_preview.php' , 'PREVIEW');
pre_window.docu ment.write(cont ent);
pre_window.docu ment.close();

but document.write will delete everything when is called... so thats not
an option as well...

My next thought is:
content = get_content('Co ntentbody');
pre_window = window.open('te st_preview.php' , 'PREVIEW');
var div = pre_window.docu ment.getElement ById("content") ;
var text = pre_window.docu ment.createText Node("my text");
pre_window.docu ment.div.append Child(text);
pre_window.docu ment.getElement ById("content") .innerHTML=cont ent;

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 2933
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(edi tor) {
if (!editor)
return '';
var text_area_conte nt;
eval('var text_area = document.getEle mentById(editor );');
text_area_conte nt = text_area.value ;
return text_area_conte nt;
}
function open_window() {
content = get_content('Co ntentbody');
pre_window = window.open('te st_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('te st_preview.php' , 'PREVIEW');
you can now address that window as pre_window. For example:
pre_window.docu ment.write(cont ent);

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
6324
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 Document.prototype.write= my_doc_write ; but it didn't work. I discovered that this seemed to work: HTMLDocument.prototype.write= my_doc_write ; Why does HTMLDocument work here but not...
1
5037
by: Nat | last post by:
Hi I have following code: ----------------- protected override void Render(HtmlTextWriter w) { if (helpString!=null) { w.Write("<span class='tooltipiconouter'><img title = '"+this.helpString+"' class='tooltipIconInner' align='center' src = '../Lib/images/questionmark.gif' a href='#' onclick = 'myWin = window.open(\"\", \"\", \"width=300,...
2
4583
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 onload="window.open('new1.html')">', this code will not work. Could you confirm this and find such syntax rule for me on the internet? Thank a lot. <html><head> </head><body> <SCRIPT...
7
2739
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: <HTML> <HEAD> <TITLE>Document.write bug</TITLE> <Script Language="JavaScript"> function load() { var w = window.open('','','');
2
2691
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 with the first document.write statement. Tried with window tried without Please help. This code pulls XML from a web site then parses it into a dynamically created table built with javascript....
4
3604
by: Nat | last post by:
Help, I have following code: ----------------------------------------------------- protected override void Render(HtmlTextWriter w) { if (helpString!=null) { w.write("<span class='tooltipiconouter'><img title = '"+this.helpString+"' class='tooltipIconInner' align='center' src =
11
5168
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 targeting response.write at it is a mystery. I need to keep the original window open as well as the new one. Can anyone help?
2
1591
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 the body looks like this: <body> <h1 align="center">Budget for <div id=vertical></div></h1> <table width="100%" cellpadding="0" cellspacing="0"> <tr...
8
7088
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 <embed> section. However, when I load my script, it overwrites the current page. Is there any way I could load a new tab or window, and put the new content into it? Here is the script I am using...
0
7570
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7859
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7930
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6210
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5472
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5187
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3600
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2068
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
896
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.