C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Articles » General »

Window.open method - a step ahead series


Posted Date: 21 Oct 2009    Resource Type: Articles    Category: General
Author: Gaurav AroraMember Level: Diamond    
Rating: 5 out of 55 out of 55 out of 55 out of 55 out of 5Points: 35



The syntax of the window.open method is given below:


open (URL, windowName[, windowFeatures])


URL

This is the URL of the page which open in the new window.
It could be blank.

windowName

A name to be given to the new window.
The name can be used to refer this window again.

windowFeatures

It contains the various window
features for the popup window i.e. status bar, address bar etc

The following lines of code, open a new browser window with standard features :


window.open ("http://interview.msdotnetheaven.com","MsDn Interview Questions");

Changing the features of the Popup


By using some stuff we can control the features of the popup.

The following code opens a window with a status bar
and no extra features:

window.open ("http://interview.msdotnetheaven.com","MsDn Interview Questions","status=1");

The code below opens a window with toolbar and status bar :

window.open ("http://interview.msdotnetheaven.com","MsDn Interview Questions","status=1,toolbar=1");


The following is the table tells the features :







































status The status bar.
toolbar The standard browser toolbar.
location The URL Location entry field.
menubar The menu bar of the window
directories The standard browser directory buttons.
resizableAllow/Disallow the user to resize the window.
scrollbars Enable the scrollbars if the document is bigger than the window
heightSpecifies the height of the window in pixels.
width Specifies the width of the window in pixels.

Example :

The Code below opens a popup window when you enter the page:


<html>
<head>


<title>Open Blank Popup WIndow </title>

</head>




<SCRIPT
language="JavaScript">


function openBlank()

{
testwindow=
window.open ("", "mywindow",

"location=1,status=1,scrollbars=1,width=100,height=100");

testwindow.moveTo(0,0);
}
</SCRIPT>




<body

onload="javascript: openBlank()">





<H1>Open Blank Popup WIndow</H1>
</body>
</html>


Here, URL is blank. This will open a blank window.

Test code here:

Open Blank Window

Popup On Exit


The following code pops up a window when the user exits a page.


<html>
<head>


<title>Window Exit Alert </title>



</head>

<SCRIPT
language="JavaScript">

function exitAlert()
{
my_window=
window.open ("",

"mywindow1","status=1,width=350,height=150");

my_window.document.write('<H1>Exiting Window... </H1>');
}
</SCRIPT>



<body
onunload="javascript: exitAlert()"

>
<H1>Window Exit Alert</H1>
</body>
</html>


Test code here: Exit Alert

Opening same url in New window:



<html>


<head>

<title>Open Same window </title>

</head>

<SCRIPT language="JavaScript">

function OpenMe()

{

var url = self.location;

window.open(url,"MySelf","left=20,top=20,width=500,height=500,toolbar=1,resizable=0");

}

</SCRIPT>



<body >

<H1>Open Same window</H1>

Test code here: <a href="javascript:OpenMe();">Open Me</a>

</body>



</html>

We can also open the current page in new window,

Test code here: Open Me

Attachments

  • Windows.Open method (34273-21735-226938-18746-windowOpenExample1.html)


  • Responses


    No responses found. Be the first to respond and make money from revenue sharing program.

    Feedbacks      
    Popular Tags   What are tags ?   Search Tags  
    Sign In to add tags.
    Windows.open  .  Javascript  .  A step ahead series  .  

    Post Feedback


    This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
    You must Sign In to post a response.
    Next Resource: Domain Names and IP Addressing
    Previous Resource: Charts in ms excel
    Return to Discussion Resource Index
    Post New Resource
    Category: General


    Post resources and earn money!
     
    More Resources



    dotNet Slackers

    About Us    Contact Us    Privacy Policy    Terms Of Use