window.location And The difference between By default, it opens in a new window

and adds the target attribute (_ By default, the browser opens in the new tab

after “blank” (url,”_ blank”);

1. window.location Is a property of the window object, and Is the method of window object

window.location Is your reference to the URL address object of the current browser window! Is used to open a new window function!

2. It’s not necessary to open a new window!!!
as long as there is a window’s name and name This window will be replaced by the second parameter in. If you use this feature, you can replace it in iframe and frame location.href .
For example & lt; iframe name = “AA” &> & lt; & iframe &>
& lt; input type = button onclick=“ (‘1. HTM ‘,’aa’, ‘) “&> and
& lt; input type = button

onclick=” self.frames [‘aa’]. location.href= ‘1. HTM’ “&> has the same effect

when making links to buttons, tables, cells, drop-down lists and div, we usually use JavaScript to complete them. Just like making ordinary links, we may need to open the link page in the current window or in a new window. At this time, we can use one of the following two items to complete them:
2 It is used to open a new window window.location It is used to replace the current page, that is, to relocate the current page
you can test it with the following example.
& lt; input type = “button” value = “new window open” onclick=“ (‘ ‘”&>
& lt; input type =” button “value =” current page opens “onclick =” window.location= ‘ ‘”&>

window.location or How to specify the target?
this is a common problem, especially when using the frame framework.
window.location Change to top.location You can link to the specified page
at the top (“your website”, “_ top”);

5. It is used to open a new window window.location It is used to replace the current page, that is, to relocate the current page

users cannot change it document.location (because this is where the document is currently displayed).
window.location It is also an object.

however, you can use window.location Change the current document (replace the current document with another document), and document.location It’s not an object.
Server redirection may cause document.url Change, but window.location.href It always refers to the URL used to access the web page.
in most cases, document.location and location.href Is the same, but when there is a server redirection, document.location Contains the URL that has been loaded, and location.href It contains the URL of the original requested document.

2 () is the address where you can open another website on one website and window.location () is a web page that can only be opened in one web site
0 () detailed explanation

& lt; script type = “text/JavaScript” &>
& lt;! — (‘ page.html ‘; — &>
& lt; & Script &>

because it is a piece of JavaScript code, they should be placed in & lt; script language = “JavaScript” &> Between tag and & lt; & Script & gt. ≪! — and — &> work for some older browsers, where the code in the tag is not displayed as text.
We should form this good habit. (‘ page.html ‘) to control the pop-up of new windows page.html , if page.html If it is not in the same path as the main window, the path should be written in the front, either absolute path (http://) or relative path (/ /). Single quotation marks and double quotation marks are OK, but don’t mix them up. This code can be added to any position of HTML, between & lt; Head &> and & lt; Head &>, & lt; body &>, or between & lt; body &>, the earlier it is executed, especially when the page code is long and you want to make the page pop up earlier.

after setting the pop-up window

let’s talk about the setting of pop-up window. Just add a little more to the code above. Let’s customize the appearance, size and location of the pop-up window to suit the specific situation of the page.
  <SCRIPT LANGUAGE=”javascript”&>
  <!– (‘ page.html ‘,’newwindow’,’height = 100, width = 400, top = 0, left = 0, toolbar = no, menubar = no, scrollbars = no, sizable = no, location = n o, status = no ‘)// this sentence should be written in a line
— &>
& lt; & Script &>

parameter explanation: Command to pop up a new window;
‘ page.html ‘the file name of the pop-up window;
‘newwindow ‘the name of the pop-up window (not the file name), which is optional and can be replaced by an empty’;
height = 100 window height;
width = 400 window width;
Top = 0

the value of “scroll” in the menu bar on the left side of the screen is “scroll = 0” and “scroll = 0”.
Re sizable = no whether the window size is allowed to be changed, yes is allowed;
location = no whether the address bar is displayed, yes is allowed;
status = no whether the information in the status bar is displayed (usually the file has been opened), yes is allowed;
& lt; script &>

control the pop-up window with functions:

the following is a complete code.
  <script LANGUAGE=”JavaScript”&>
  function openwin() { (” page.html “,” newwindow “,” height = 100, width = 400, toolbar = no, menubar = no, scrollbars = no, reusable = no, location = no, status = no “)// write in a line
// — &>
& lt; script &>
& lt; Head &>
& lt; body onload = “openwin()” &>
any page content…
& lt; & Body &>
& lt; ml &>

here, we define a function openwin(), whose content is to open a window. There is no use until it is called. How to call it?

method 1: & lt; body onload = “openwin()” &> the browser will pop up when reading the page;
method 2: & lt; body onload = “openwin()” &> the browser will pop up when leaving the page;
method 3: call with a connection:
& lt; a (?) “onclick =” openwin() “&> open a window & lt;/A &>
Note: the “#” used is a virtual connection.
Method 4: call with one button:

two windows will pop up at the same time:

slightly change the source code:

& lt; script language = “JavaScript” &>
& lt; !–
  function openwin() { (” page.html “,” newwindow “,” height = 100, width = 100, top = 0, left = 0, toolbar = no, menubar = no, scrollbars = no, sizable = no, location = n o, status = no “)// write a line
in Chinese (“page2.html”, “newwindow2”, “height=100, width=100, top=1 00, left=100,toolbar=no, menubar=no, scrollbars=no, Re sizable = no, location = no, status = no “)// write it in a line
// — &>
& lt; & Script &>
to avoid covering the two pop-up windows, use top and left to control the pop-up position, and do not cover each other. Finally, use the four methods mentioned above to call.
Note: the names of the two windows (newwindows and newwindows2) should not be the same, or they should all be empty.

[open the file 1.htm in the main window and pop up a small window at the same time page.html 】

add the following code to the & lt; Head &> section of the main window:
& lt; script language = “JavaScript” &>
& lt;! —
function openwin() {
0 (” page.html “,””,”width=200,height=200″)
  < /Script &>
to join the & lt; body &> section:
& lt; a (<1. HTM) onclick = "openwin()" &> open & lt;/A & gt.

[timing closing control of pop-up windows]

next, we will control the pop-up windows, and the effect will be better. If we add a small piece of code to the pop-up page (Note: add) page.html In HTML, it’s not in the main page, otherwise…), is it cooler to let it close automatically after 10 seconds?
First, add the following code page.html The & lt; Head &> section of the file:
& lt; script language = “JavaScript” &>
function closeit()
setTimeout(“ self.close () “, 10000)// MS
& lt; & Script &>
and then & lt; body onload =” closeit() “&> This sentence replaces page.html The original & lt; body &> sentence is OK. Don’t forget to write this sentence! The function of this sentence is to call the code to close the window and close the window after 10 seconds. )
[add a close button in the pop-up window]

& lt; form &>
& lt; input type =’button ‘value =’close’) {
open window document.cookie= “Popped = yes”