Window object is the root of the DOM from which descend all the other elements that constitute the document and the window that contains it. JavaScript allows the management and control of the browser windows, and all the elements incorporated in them, of course with appropriate restrictions of the case (eg it is not possible to read the list of favorites).
Open a new window, it means access to new content without losing sight of the previous ones. With HTML you can open the contents of a link in a new window or tab in the new browser through the use of target = “_blank”, but with JavaScript you have a more advanced control. The method to open a new window:
window.open (url, name, features, replace)
The first argument is the address of the document to display in the new window, the second is the name of the new window and also works as an identifier, and the third are actually a number of characteristics such as length, height, position in screen or if the window can be resized (find all the features in the theoretical study of the method that you can find on any site that deals with JavaScript, like this one), and finally the last boolean indicating if the address creates a new value, or it can replace one in the history. As an example we create a test.html document and insert it in a new window from the page index.html.
<!-- File Test.html --> <html> <head><title>New Document</title></head> <body> <center><h1>New Document</h1></center> </body> </html <!-- File Index.html --> <html> <head><title>Main Document</title> <script language="javascript"> function open_window() { window.open("test.html", "_blank", "left=100, top=100, width=200, height=200") } </script> </head> <body> <input type="button" value="Open Document" >To close the window with which you are working is done by calling the window.close() method, otherwise it is necessary to invoke the method on the object that you created earlier, in fact the window.open(…) returns a new window.
var nf = window.open(“test.html”, …);
nf.close();We can operate on a window through other methods, resize it, change its position or move the scroll bar of the document. The address bar of your browser is identified by window.location, by this you can read or send the browser to a particular address, it is available on the window.location.href string that is none other than the address bar of the browser . Also noteworthy is window.location.reload() which is equivalent to pressing the F5 key to reload the document.
The status bar is used to display messages to the user, thanks to window.status can be accessed by inserting personalized messages. Another object is particularly interesting window.history which is nothing other than the browser history and it is thus possible navigarvici forward and backward.
Other windows very important manageable with JavaScript are modal, ie those that are used to give information or have simple user input. The methods are alert(), confirm() and prompt(). The first simply shows a message to the visitor, the second allows the user to give a yes or no answer to a question, and finally the third that allows the visitor to enter a keyboard input returns it as a string.