Google Answers Logo
View Question
 
Q: "Pop up window" ( Answered,   1 Comment )
Question  
Subject: "Pop up window"
Category: Computers > Programming
Asked by: dukebird-ga
List Price: $25.00
Posted: 26 Sep 2002 18:50 PDT
Expires: 26 Oct 2002 18:50 PDT
Question ID: 69534
How do I create a pop up window in a web page that I can put text or a
picture in? Can you maybe send me an HTML code for the window and all
I have to do is change a few things or twick it so to speak?
Answer  
Subject: Re: "Pop up window"
Answered By: robertskelton-ga on 26 Sep 2002 21:02 PDT
 
Hi there,

I have found some HTML/Javascript code that allows either plain text
or an image file to appear in a pop up window.

The original code is at: 

Put anything you want in a pop up window
http://webdeveloper.earthweb.com/webjs/item/0,,12760_29601_viewit,00.html

I've trimmed it to make it easier to follow:

--------------------

<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
<title>Put anything you want into a popup window</title>
</head>

<body onUnload=winClose();>

<script language=JavaScript> 
<!--
var NewWin=null
function openNewWin() {
	if(NewWin && !NewWin.closed) NewWin.close()
	NewWin=window.open("", "NewWin",
"resizable=yes,scrollbars=yes,height=200,width=580,top=100,left=0");
	NewWin.document.write("<head><title>Text</title></head>") 
	NewWin.document.write("<body>")
	NewWin.document.write("PLACE TEXT HERE<br>")
	NewWin.document.write("PLACE MORE TEXT HERE<br>")
	NewWin.document.write("</body>") 
} 
var NewWin2=null
function openNewWin2() {
	if(NewWin2 && !NewWin2.closed) NewWin2.close()
	NewWin2=window.open("", "NewWin2",
"resizable=no,height=165,width=200,top=350,left=400");
	NewWin2.document.write("<head><title>Images</title></head>") 
	NewWin2.document.write("<BODY topmargin='0' leftmargin='0'
marginheight='0' marginwidth='0'>")
	NewWin2.document.write("<center><img
src='IMAGEFILENAME.JPG'></center>")
	NewWin2.document.write("</body>") 
}

function winClose(){
	if(NewWin && !NewWin.closed) NewWin.close()
	if(NewWin2 && !NewWin2.closed) NewWin2.close()
}
//--></SCRIPT> 

<p><i>examples:&nbsp; </i><br>
<a href="#" onClick="openNewWin();return false;">Text</a><br>
<a href="#" onClick="openNewWin2();return false;">Image</a>
</p>

</body>
</html>

--------------------

All you need to change is the CODE IN CAPITALS, and the window
sizes...

IMAGE
=====

The image is very straightforward: just replace IMAGEFILENAME.JPG with
a local image file name, like mypicture.jpg, or an external image like
http://website.com/image.gif

Then, four lines above IMAGEFILENAME.JPG you need to change the
dimensions of the window to fit the size of the image you are
displaying.


TEXT
====

The text is almost as easy: just replace PLACE TEXT HERE with the text
you want. For each new line of text just insert extra lines like this,
one after the other:

NewWin.document.write("PLACE MORE TEXT HERE<br>")

Again, three lines above you need to change the dimensions of the
window to fit the size of the image you are displaying. If the text
doesn't fit, there will be scroll bars.

OTHER
=====

- The pop-ups will close automatically when the main page is closed.
It is also impossible to keep clicking on a link and get multiple
pop-ups.

- Any HTML code can be placed between the quotes in lines like this:

NewWin.document.write("<body>")

except if the HTML itself has quotes, then you must replace any
"double quotes" with 'single quotes'. To see more examples, go to the
original code linked to above, save it as a .html file and view it in
your browser.

- In the same line as the window sizes you can have either:

resizable=yes
resizable=no

for whether or not you want the viewer to be able to change the size
of the pop up window.

------------------

Search strategy:

"pop-up window" javascript "plain text"
://www.google.com/search?q=%22pop-up+window%22+javascript+%22plain+text%22


Be sure to ask for a clarification if in anyway this code does not
suit your purposes.

Best wishes,
robertskelton-ga

Clarification of Answer by robertskelton-ga on 26 Sep 2002 21:09 PDT
A better link to the original code (and a demo) is:
http://webdeveloper.earthweb.com/webjs/item/0,3602,12760_29601,00.html

Clarification of Answer by robertskelton-ga on 26 Sep 2002 21:43 PDT
Hmmm... I tried to cut and paste the code as it appears above and it
didn't work - must be a stray space or two in the code (Javascript can
be very intolerant of this).

A working version of the same code can be found at:
http://searchenginez.com/popupcode.html
Comments  
Subject: Re: "Pop up window"
From: prophet-ga on 27 Sep 2002 21:56 PDT
 
Since you're going to add the text or graphics in advance anyway,
putting dynamic content into the pop-up window is a more complicated
solution than you really need.

By far the easiest thing to do is create a separate html file (let's
call it "new.html") with the image in it, or text, or whatever else
you'd like in there.  Then in your original document, just include a
link like:

<A href="new.html" target="_blank">launch new window</a>

If all you want is a picture with no formatting, you can reference it
directly like:
<a href="image.gif" target="_blank">launch image</a>

You can link as many files as you want in this way and they'll all pop
up in new windows when you click on their link.

Hope this helps,
Prophet

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy