Controlling Windows with JavaScript
We used over 10 web hosting companies before we found Server Intellect. They offer dedicated servers, and they now offer cloud hosting!
To begin, let’s go ahead and create a fresh HTML file to work in just to demonstrate the functionality that we are trying to create.Now let’s go ahead and begin on opening a new window for the user. To do so we will be using the JavaScript property “window.open.” We will need to set the href to the site location and also use the target attribute to name the window itself, in case we need to refer back to that particular window.
var targetWin = window.open(pageURL, title)
var targetWin = window.open(pageURL, title, 'toolbar=yes, location=no, directories=no, status=no, menubar=yes, scrollbars=no, resizable=no, copyhistory=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
We moved our web sites to Server Intellect and have found them to be incredibly professional. Their setup is very easy and we were up and running in no time.
function PopupCenter(pageURL, title, w, h) {
var left = (screen.width / 2) - (w / 2);
var top = (screen.height / 2) - (h / 2);
We have now created a new window using JavaScript, but can we close the same page in a similar fashion? The answer is yes!
Now you can see why we set the target element in case we would ever need to refer to the window just created, like now!
In order to close the newly created window, or any window, we will be using the “window.close” function. We will be targeting the window by URL and by target attribute. I will also be setting an alert to inform the user that the window is being closed. I will now be setting an input control’s, button’s, OnClick event equal to our close event.
function CloseWindow(pageURL, title) {
alert("Window will be closed");
window.close(pageURL, title);
}
We stand behind Server Intellect and their support team. They offer dedicated servers, and they are now offering cloud hosting!
JavascriptWindowsTut.zip