Referencing a new window
Referencing elements in a new window
Is a "new window" any different to a "popup window", basically the answer is no.
The method used to do either is relatively the same, I suppose the real difference would be in the size of the new window. Small windows tend to be classed as popups.
The information on this page will show you how you can open your new window using both the inline and script methods, and how to size and place a window.
The basic code for opening a new window is
<a href="yourpage.htm" target="_blank">Example 1</a>
<a href="yourpage.htm" target="_blank" onclick="window.open(this.href, this.target); return false">Example 2</a>
The above links opened a new full sized window, to have the window open in a size and position of your choosing attributes can be added.
<a href="your_page.htm" target="_blank" onclick="window.open(this.href, this.target,'width=300,height=100,left=450,top=250,toolbar=yes');return false">Example 3</a>
In the event that you do want to load a page into the current window and another page into a new window you would use something like this.
<a href="page1.htm" onclick="window.open('page2.htm','win1','left=100,top=300,width=300,height=300')">Load 2 Pages</a>
Notice there is no target="_blank" or return false
When creating new windows using a function you assign the window object (your new window) to a variable (windowHandle), you may also include a window name. Although the window name is optional you must still include the single quotes if not used.
The following script will open new windows of the stated size and in the stated position, the page to be loaded into the new window is passed to the function when a link is clicked.
<script type="text/javascript">
<!--
function openWindow(url){
newWin = open(url,'','width=200,height=100,top=300,left=250' )
}
//-->
</script>
<a href="your_page1.htm" onclick="openWindow(this.href) ; return false">Example 4a</a>
<a href="your_page2.htm" onclick="openWindow(this.href) ; return false">Example 4b</a>
If you do not include a name a new window is opened with every click of every link, click the above links a few times and see how many windows open even from the same link, you may have to look at your taskbar
If you give the window a name your page is loaded into the same new window.
<script type="text/javascript">
<!--
function openWindow(url){
newWin = open(url,'winName','width=200,height=100,top=300,left=250' )
}
//-->
</script>
<a href="your_page1.htm" onclick="openWindow(this.href) ; return false">Example 5a</a>
<a href="your_page2.htm" onclick="openWindow(this.href) ; return false">Example 5b</a>
You can make the script even more flexible by passing additional arguments to the function for example the width, height, left and top position.
This will allow you to have different sized windows in different positions.
<script type="text/javascript">
<!--
function openWindow(url,Left,Top,Width,Height,atts){
var newWin=open(url,'','left='+Left+',top='+Top+',width='+Width+',height='+Height+',attributes='+atts+'' )
}
// -->
</script>
<a href="page1.htm" onclick="openWindow(this.href,100,100,400,200,'toolbar=yes,location=yes');return false">Example 6</a>The above script does not use a window name so that a seperate window is opened for each link.
Although it is possible to use the same window in this way it does require some extra coding other than just including the name, you can see how it is done in Reusing Popups
If a script is going to be used to open the new windows then instead of adding return false to all the links you can add return false to the end of the function.
function openWindow(){
var newWin=open()
return false
}
For this method you would have to add the word return immediately before the function call within the onclick event.
onclick="return openWindow()
Now that we have enough information to open single or multiple windows any size and in any position the next step is to learn how to reference a new window.
window.open('page.htm','windowName')
Referencing a new window
Referencing elements in a new window
Each attribute must be separated by a comma.
<a href="yourpage.htm" onclick="self.resizeTo(600,480)"> Your Link</a>