473,783 Members | 2,354 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_previe w() {
var newWin =
window.open('/weblog/pop_up.html','P review','width= 650,height=400' );

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

var insertPoint_Tex t = newWin.document .getElementById ('pre'); var
content_Text = newWin.document .createTextNode (previewText);
insertPoint_Tex t.appendChild(c ontent_Text);

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

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

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

Code:

function generate_previe w() {
var newWin =
window.open('/weblog/pop_up.html','P review','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.previe w.src;

var insertPoint_Tex t = newWin.document .getElementById ('pre'); var
content_Text = newWin.document .createTextNode (previewText);
insertPoint_Tex t.appendChild(c ontent_Text);

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

var insertPoint_Ico n = newWin.document .getElementById ('icon');
insertPoint_Ico n.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 1530
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
1844
by: Andy | last post by:
Hi, I am complete JavaScript novice and would really appreciate some help with this code: ===================================================================== <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%> <!--#include file="Connections/ssdb.asp" -->
2
2858
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 presume the best way to create the popup is by using a layer with javascript hide and show... I intend to use a database to store the pictures in and the use the users full name to build a relationship between the database with the images and the...
2
1699
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 to the C program, also I need to pass the lengths of the work areas. I have exhausted my limited knowledge of C is there any of you folks that can provide some assistance. I will tell you right now, i am one of those old dinosaurs that still...
2
1289
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 weird error. Can anyone determine what the error means and what part of the code would produce this? http://www.thesecondchancemovie.com/_site/mediaplayer/index.php?id=59a362eacbeaeda153f8e3fdf493c508 THanks in advance, Tim
22
2334
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 some things I heard in the past that I thought someone could clarify. On Page 6 it states "ASP.NET web pages (and web services) are executed within the CLR (common language runtime), so they can be authored in any language that has a...
7
1404
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
3140
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 numbers. Now i use this script for validate the email address. But it allows the cpital letters otherwise its working correctly. SCRIPT FUNCTION ************************************************
10
7365
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 this ERROR. By th way, I'm using a Joomla 1.5.3 site. The URL: http://www.dutchmarshalls.com/index.php/service/51-service/87-price-and-product-list- The ERROR CODE:...
5
1471
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 explanation of that content. The explanation of the content i have given as text. Pls help me. Thanks in advance. Deeps
0
9480
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10313
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10081
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8968
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5378
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4044
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
2
3643
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2875
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.