Many Beginer Web Developers wonder how they can open a new web page in a new web browser and setting some options for it.
Using the HyperLink Control
It is simply an easier way; you only have to set the value of the property "Target" to "_blank" as shown:
This section will be divided it into two sub-sections; they are somehow the same but with minor differences. The sub-sections will be one for the client side controls and the other for the server side controls.
window.open( [sURL] [, sName] [, sFeatures] [, bReplace])
- URL: Optional. The URL of the page to open in the new window. This argument could be blank.
- Name: Optional. A name to be given to the new window. The name can be used to refer this window again.
- Features: Optional. contains a list of items separated by commas. Each item consists of an option and a value, separated by an equals sign (like status bar, address bar etc).
- Replace: Optional. Boolean that specifies whether the sURL creates a new entry or replaces the current entry in the window's history list. This parameter only takes effect if the sURL is loaded into the same window.
After being familiar to the parameters of the method I will list some of the features that you can use:
||Specifies whether to display the browser in full-screen mode.
||Specifies the height of the window in pixels
||Specifies the left position, in pixels.
||Specifies the top position, in pixels.
||specifies the width of the window in pixels.
||Specifies whether to display the navigation bar.
||Specifies whether to display the menu bar.
||Allow/Disallow the user to resize the window.
||Enable the scrollbars if the document is bigger than the window.
||Specifies whether to add a Status Bar at the bottom of the window.
||Specifies whether to display a Title Bar for the window.
||Specifies whether to display the browser command bar, making buttons such as Favorites Center, Add to Favorites, and Tools available.
First I will talk about using the window.open() method in the client side. All what you need to do is to write this line of code in the function of the client side control:
This line of code will open the "Default2.aspx" web page in a new browser with the features set on the function parameters.
Second I will talk about using the same method but in the code behind which means in the server side. Lets check this block of code and explain what will happen :
protected void Button1_Click(object sender, EventArgs e)
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("'top=0, left=0, width=500, height=500, menubar=yes,toolbar=yes,status=1,resizable=yes'));
Type t = this.GetType();
if (!ClientScript.IsClientScriptBlockRegistered(t, PopupScript))
ClientScript.RegisterClientScriptBlock(t, PopupScript, sb.ToString());
In part 1 it is the same code as in the client side subsection. Without part 2 the page "Default2.aspx" will not be opened because you have not register the client script block yet. In the code you check for the script block by its name(key),if not exist then you add it else nothing happens.
I encountered something that I found it helpful.what shall you do if you want to make the new browser open in the maximized mode? You can use the properties "screen.availwidth" and "screen.availheight" to set the widht and height of the features of the window.open() method respictivley as follows:
sb.Append('top=0, left=0, width='+screen.availwidth+', height='+screen.availheight+', menubar=yes,toolbar=yes,status=1,resizable=yes'));
I hope this article has been helpful to those of you who queried how to open new web pages in new web browser windows, and I urge those of you who have other comments or tidbits to speak out, and for those with further queries please do not hesitate to ask. Leave a post and we'll get to you as soon as humanly possible!