Hello and welcome to the Webmasters Forums!. This is the best place to get webmasters resources for free. Get $2 for free today, read more - Make your payment today. Download premium and professional templates for free. Get free web hosting without ads, read more. You can get lot more by simply join with this forum. To gain full access to the forums you must sign up for a free account.


Post Reply  Post Thread 

Opening a New Window in Java Script

Post Bank
Posting Manager
******

Posts: 995
Group: Forum Team
Joined: Sep 2006
Status: Online
Make money from now. You can make money just for posting on this forum. Every discussions on this community gives you more money. $2 minimum payout. So get your payment today, SignIn with this forum.

Signin to Remove this Post

ivenms
Administrator
*******


Posts: 2,179
Group: Administrators
Joined: Sep 2006
Status: Offline
Reputation: 14
Points: 4389 (Donate)
Post: #1

Rolleyes Opening a New Window in Java Script


To open a new window, you will need to use yet another ready-made JavaScript function. Here is what it looks like:

window.open('url to open','window name','attribute1,attribute2')

This is the function that allows you to open a new browser window for the viewer to use. Note that all the names and attributes are separated with a comma rather than spaces. Here is what all the stuff inside is:

'url to open'
This is the web address of the page you wish to appear in the new window.

'window name'
You can name your window whatever you like, in case you need to make a reference to the window later.

'attribute1,attribute2'
As with alot of other things, you have a choice of attributes you can adjust.

Window Attributes

Below is a list of the attributes you can use:

width=300
Use this to define the width of the new window.

height=200
Use this to define the height of the new window.

resizable=yes or no
Use this to control whether or not you want the user to be able to resize the window.

scrollbars=yes or no
This lets you decide whether or not to have scrollbars on the window.

toolbar=yes or no
Whether or not the new window should have the browser navigation bar at the top (The back, foward, stop buttons..etc.).

location=yes or no
Whether or not you wish to show the location box with the current url (The place to type http://address).

directories=yes or no
Whether or not the window should show the extra buttons. (what's cool, personal buttons, etc...).

status=yes or no
Whether or not to show the window status bar at the bottom of the window.

menubar=yes or no
Whether or not to show the menus at the top of the window (File, Edit, etc...).

copyhistory=yes or no
Whether or not to copy the old browser window's history list to the new window.

All right, here's an example code for opening a new window:

<FORM>
<INPUT type="button" value="New Window!" onClick="window.open('http://www.pageresource.com/jscript/jex5.htm','mywindow','width=400,height=200')">
</FORM>


Some Important Rules

Before we move on, we need to make note of some things so you won't go insane like I did trying to get this to work right!

When you get to the INPUT tag, keep everything in that tag on one single line in your text editor, including the javascript commands. (The text goes to the next line on this page so you can print it out easily).

Once you come to the onClick=" ", don't leave any spaces between anything. Just use the commas and the quote marks. Any white space will keep it from working correctly in Netscape.

Don't put quote marks around the yes, no, or numbers for the attributes. You only use single quotes around the entire set of attributes.

In some browsers, you may need to substitute the number 1 for yes, and the number zero for no in the attributes section. The yes or no should work fine, though.

A New Browser Window

Okay, enough rules. Let's look at the code that makes a completely new browser! Basically, you just use yes for all of the attributes. Here is the code:

<FORM>
<INPUT type="button" value="New Window!" onClick="window.open('http://www.pageresource.com/jscript/jex5.htm','mywindow','width=400,height=200,toolbar=yes,
location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=y es,
resizable=yes')">
</FORM>


Remember, keep everything on one line....one really, really long line! I just put the sample code on new lines so you wouldn't have to scroll forever to read everything........and your printer won't go crazy now either!

Closing a New Window

Hmm.....what's with the "Close Window" button you saw in the new window? How does one do do that? To use that trick, use the window.close() function in the HTML of the new window. Just put this code wherever you want the close button to show up in the new window:

<FORM>
<INPUT type="button" value="Close Window" onClick="window.close()">
</FORM>

Of course, the window can be closed with the "x" symbol on the top-right of the window as well.

Set the Window Position

There is another set of options you can use to set the position of the new window on the viewers, but it only works with NS4+ and IE4+:

screenX=number in pixels
Sets the position of the window in pixels from the left of the screen in Netscape 4+.

screenY=number in pixels
Sets the position of the window in pixels from the top of the screen in Netscape 4+.

left=number in pixels
Sets the position of the window in pixels from the left of the screen in IE 4+.

top=number in pixels
Sets the position of the window in pixels from the top of the screen in IE 4+.

Great, but how do you decide which commands to use if there are different ones for each browser? In this case, you can use both sets of commands- the browser will ignore the set it does not recognize. The example below will give you a new window 0 pixels from the left and 100 pixels from the top of your screen:

<FORM>
<INPUT type="button" value="New Window!" onClick="window.open('jex5.htm','mywindow','width=400,height=200,left=0,top=100,screenX=0,screenY=100')">
</FORM>


Read: General Rules & Policies before posting.
Make Money By Posting | Earning and Exchanging Points | Add Your Links
15-09-2006 03:25 AM
Find all posts by this user Quote this message in a reply
dotbost
Newbie


Posts: 7
Group: Registered
Joined: Sep 2006
Status: Offline
Reputation: 0
Points: 0 (Donate)
Post: #2

RE: Opening a New Window


very nice tutorials. Helps a lot

23-09-2006 03:34 PM
Find all posts by this user Quote this message in a reply
yaldex
Newbie


Posts: 2
Group: Registered
Joined: Oct 2006
Status: Offline
Reputation: 0
Points: 0 (Donate)
Post: #3

RE: Opening a New Window


Thanks very much, just searched for this information, it very is useful to me


http://www.yaldex.com/ Free scripts
26-10-2006 12:33 AM
Visit this user's website Find all posts by this user Quote this message in a reply
clookid
Advanced Member
***


Posts: 184
Group: Registered
Joined: Oct 2006
Status: Offline
Reputation: 4
Points: 134 (Donate)
Post: #4

RE: Opening a New Window


Very long tutorial but very imformative! How long did it take you to write?


Veebra Articles - Computer and technology related articles.
28-10-2006 06:56 AM
Find all posts by this user Quote this message in a reply
walsh
Senior Member
****


Posts: 401
Group: Registered
Joined: Oct 2006
Status: Offline
Reputation: 0
Points: 680 (Donate)
Post: #5

RE: Opening a New Window


Whaooo........

This could be very useful for me. New window on click is now days very useful and it is normally used with the buttons.


25-07-2007 09:33 PM
Find all posts by this user Quote this message in a reply
Dhanraj
Senior Member
****


Posts: 272
Group: Registered
Joined: Aug 2007
Status: Offline
Reputation: 1
Points: 99 (Donate)
Post: #6

RE: Opening a New Window in Java Script


yup very useful script just doing the same work of pop up generator
is it possible to generate the window in different modes
that is i mean when a person enters to a page,suddenly a window generates,like that


Free cash for surveys

Our Great indian forum

Pretty good PTC-Real

Anonymize your links
19-09-2007 02:01 AM
Visit this user's website Find all posts by this user Quote this message in a reply
ivenms
Administrator
*******


Posts: 2,179
Group: Administrators
Joined: Sep 2006
Status: Offline
Reputation: 14
Points: 4389 (Donate)
Post: #7

RE: Opening a New Window in Java Script


Dhanraj Wrote:
is it possible to generate the window in different modes
that is i mean when a person enters to a page,suddenly a window generates,like that


You can generate a popup on loading of a page by putting the code on even onto a function and calling it on onLoad event.


Read: General Rules & Policies before posting.
Make Money By Posting | Earning and Exchanging Points | Add Your Links
19-09-2007 02:05 AM
Find all posts by this user Quote this message in a reply
Lord_Daksh
Posting Freak
*****


Posts: 643
Group: Registered
Joined: Sep 2007
Status: Offline
Reputation: 0
Points: 16 (Donate)
Post: #8

RE: Opening a New Window in Java Script


I want a trick,by which with a single click,two windows wil get opened. So is there any such script?


EARN EASY 50$ IN 10 DAYS!
FREE CALLS,GPRS,SMS,MMS TRICKS,FULL MOVIES,FREE RAPIDSHARE
80$ IN 1 DAY! 20$/REFERRAL!!
22-09-2007 04:40 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Post Reply  Post Thread 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
Toungue Image Rollover Script Javascript ratedguy 0 77 14-07-2008 06:15 PM
Last Post: ratedguy
  Free Sudoku Script ivenms 6 978 23-07-2007 06:15 AM
Last Post: ivenms
Shy Logical Operators and Conditional Statements - Java Script ivenms 0 698 15-09-2006 03:17 AM
Last Post: ivenms
  Declaring Variables and Functions on Java Script ivenms 0 587 15-09-2006 03:13 AM
Last Post: ivenms

View a Printable Version
Send this Thread to a Friend
Subscribe to this Thread | Add Thread to Favorites
Rate This Thread:

Forum Jump:

Sign In to Remove Ads

Download 1000's of web templates. Unlimited access!
World's Best Web Hosting
Website of the Month

Create-a-Page for Free
SOTM June 2008


Accepting Submissions
for July 2008
Resources

Recommended Sites:



Visit our Sponsors!

Current time: 08-10-2008, 12:51 PM


Copyright © 2002-2008 MyBB Group
Powered By MyBB