logo
Published on Technical articles on: Windows servers, Apache Web Server, MySQL, PHP, IIS (http://www.sitebuddy.com)

Javascript: Open a custom new browser window within your html code

By chris
Created 23 Feb 2006 - 9:19am

Whatz up Andre!


1) The JavaScript function to open a new browser (remember this is also called a popup...many tools will block it) is:
window.open("URL","Name","Optional_Windows_Attributes")

With:
URL(required): URL to the target.
Can be a relative path like myGreatPageName.htm or absolute http://www.sitebuddy.com
Name(optional): is the name of the new windows, it can be empty: ""
Optional_Windows_Attributes(optional): a comma separated list of Window properties/attributes.

The Windows attributes can be any of:
width: in pixel example, width=500
height:  in pixel example, height=400
left: in pixel offset from the left side of the screen, example left=100
top: in pixel offset from the top of the screen, example top=100
toolbar: 0 or 1 to indicate if the new window should have the toolbar (back, forward ...)
location:  0 or 1 to indicate if the new window should have the location bar (where you enter URLs ...)
directories: 0 or 1 to indicate if the new window the should have the "bookmars, what's new..." bar
status
:  0 or 1 to indicate if the new window should have the status bar (the bar at the bottom of the browser...)
scrollbars:  0 or 1 to indicate if the new window should have the scrollbars
resizable:  0 or 1 to indicate if the new window should be resizable
menubar:  0 or 1 to indicate if the new window should have menus
titlebar:  0 or 1 to indicate if the new window should a title bar
fullscreen:   0 or 1 to indicate if the new window should use the full screen

2) Now define a JavaScript function:
Note you could skip this step and call directly the "window.open" function, within the HTML (see example later).

<script>
function loadwindow(){
window.open("http://www.sitebuddy.com/view/MySQL","","width=500,height=400,status=1")
}
</script>

3) Now how to call your JavaScript function:

<form><input type="button" onClick="loadwindow()" value="Load Window"></form>

or:

<a href="" onclick="loadwindow()">Sitebuddy.com rocks>Sitebuddy.com rocks</a>

Sitebuddy.com rocks

or:

<a href="javascript:void(0)" onclick="javascript:window.open('http://www.sitebuddy.com/view/MySQL','MyWindow','width=500,height=400,status=0,toolbar=0, location=0,resizable=0,menubar=0,titlebar=0'); return true;">Sitebuddy.com check out those MySQL article, they rock</a>

Sitebuddy.com check out those MySQL article, they rock


Source URL:
http://www.sitebuddy.com/misc/javascript/open/window/1