473,395 Members | 1,941 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Need a javascript guru (I need help!)

Ok, I wrote my own weblog and I'm working on the web interface for
adding/editing my posts. I decided to add a little preview button...when
the button is clicked it is suppose to open a pop-up window. I wrote the
whole preview function in javascript so that I don't have to reload the
page to see a preview.

Here is the code I wrote that doesn't work at all:

Code:

function generate_preview() {
var newWin =
window.open('/weblog/pop_up.html','Preview','width=650,height=400');

var previewText = document.forms[0].logtext.value; var previewTitle =
document.forms[0].title.value; var previewIcon = document.preview.src;

var insertPoint_Text = newWin.document.getElementById('pre'); var
content_Text = newWin.document.createTextNode(previewText);
insertPoint_Text.appendChild(content_Text);

var insertPoint_Title = newWin.document.getElementById('title'); var
content_Title = newWin.document.createTextNode(previewTitle);
insertPoint_Title.appendChild(content_Title);

var insertPoint_Icon = newWin.document.getElementById('icon');
insertPoint_Icon.src = previewIcon;
}

And here is the code that works flawlessly to generate the preview:

Code:

function generate_preview() {
var newWin =
window.open('/weblog/pop_up.html','Preview','width=650,height=400');
newWin2=window.open();
newWin2.close();

var previewText = document.forms[0].logtext.value; var previewTitle =
document.forms[0].title.value; var previewIcon = document.preview.src;

var insertPoint_Text = newWin.document.getElementById('pre'); var
content_Text = newWin.document.createTextNode(previewText);
insertPoint_Text.appendChild(content_Text);

var insertPoint_Title = newWin.document.getElementById('title'); var
content_Title = newWin.document.createTextNode(previewTitle);
insertPoint_Title.appendChild(content_Title);

var insertPoint_Icon = newWin.document.getElementById('icon');
insertPoint_Icon.src = previewIcon;
}

It absolutely will not work unless I add these two lines:

Code:

newWin2=window.open();
newWin2.close();
It's really weird and I don't know how to fix the problem without opening
another window other than the one that I'm generating the preview in. I'm
not a programmer and I'm not that great with javascript, so if a
javascript guru could point me in the right direction I would really
appreciate it.
Jul 23 '05 #1
1 1489
Lee
Jarrod Hyder said:
It absolutely will not work unless I add these two lines:

Code:

newWin2=window.open();
newWin2.close();
It's really weird and I don't know how to fix the problem without opening
another window other than the one that I'm generating the preview in. I'm
not a programmer and I'm not that great with javascript, so if a
javascript guru could point me in the right direction I would really
appreciate it.


window.open() returns before the window actually exists.

Those lines are creating enough of a delay to allow your newWin to
open and render content and be ready for you to start manipulating
its document object.

Since you're opening an HTML page in that window, one option would
be to put script in that page that loads the content from the
opener window, so that it pulls new content when it is ready,
instead of having the opener window start pushing it too soon.

Jul 23 '05 #2

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

Similar topics

3
by: Andy | last post by:
Hi, I am complete JavaScript novice and would really appreciate some help with this code: ===================================================================== <%@LANGUAGE="VBSCRIPT"...
2
by: Tim::.. | last post by:
Hi I'm trying to create a little application that shows an image of a user when you mouseover there details in a datagrid. The datagrid is populated from an Active Directory Database and I...
2
by: jdechiricio | last post by:
Hello, I am a new to this board and came here out of desparation.... I need to modifiy a C program to allow the workareas (there could be up to 30) it uses to be defined externally and passed...
2
by: Chewbacca | last post by:
We have a program that watches a file directory and various databases, extracts the content and builds web pages dynamically. The data collection part seems to work fine, but the pages generate a...
22
by: the_grove_man | last post by:
I purchased a book titled "Pro ASP.NET 2.0" to get up to speed on web stuff because I ususally do Windows Form Applications.. But in the first chapters I was reading this week it brought to mind...
7
by: Paul J. Dudley | last post by:
I need a javascript to solve for X as in the following: 120.85 X ----- = --- 16 24 24 x 120.85 / 16 = X X = 181.28
1
by: saravanatmm | last post by:
I need javascript code for validate the email address. Email address field cannot allowed the capital letters, special characters except '@' symbol. But can allowed the small letters, numeric...
10
by: Dutchmarshalls | last post by:
Hi All, I'm using a Pay Pal form script, but locally tested in Dreamweaver with a browser it will do exactly what I'm aspect it to do. Only when I'm uploaded the file on the server it will give...
5
by: deegeorge | last post by:
Hi, I am creating a help document in asp.net.In that first i am giving the contents as links using anchor tag. When i am clicking one of the link it need to navigate to the corresponding...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.