There are many uses of location.href in javascript, mainly as follows.
self.location.href="/url" The current page opens the URL page
location.href="/url" The current page opens the URL page
windows.location.href="/url" The current page opens the URL page, and the first three usages are the same.
this.location.href="/url" The current page opens the URL page
parent.location.href="/url" Open a new page on parent page
top.location.href="/url" Open a new page on top page
If the frame is customized on the page, you can change the parent self top to the name of the custom frame. The effect is to open the URL address in the frame window
In addition, window.location.href=window.location.href; and window.location.Reload() are both refreshing the current page. The difference is whether there are submitted data. When data is submitted, window.location.Reload() will prompt whether to submit it, window.location.href=window.location.href; it will submit data to the specified url
When writing ASP.Net programs, we often encounter the problem of jumping pages. We often use Response.Redirect to do ASP.NET framework page redirect. If the customer wants to use prompts when jumping, this will not be effective, such as:
The code copy is as follows:
Response.Write("< script>alert('Congratulations, registration was successful!');< /script>");
Response.Redirect("main.html");
At this time, our prompt content jumped before it came out, and there was no difference between Response.Redirect("main.html");
At this time, we use the following code to experiment:
Another implementation of ASP.NET framework page jump
The code copy is as follows:
Response.Write("< script language=javascript>alert('Congratulations, registration was successful!')< /script>");
Response.Write("< script language=javascript>window.location.href='main.html'< /script>");
This fulfills our requirements, and after the prompt, jump to the page.
The most important thing is that the window.location.href statement can implement the page of one framework to refresh the page of another framework after executing the server-side code (Response.Redirect cannot reach it, at least I did not find it):
For example: There are two frames in the index.htm page, frameLeft and frameRight, and then refresh the page in frameLeft after executing server-side code in the frameRight page.
The most common thing before was that after registration, the login box was automatically refreshed and the login box was replaced with a login page. As long as a paragraph is added after the successfully registered code, the page of another frame can be refreshed. The code is as follows:
The code copy is as follows:
Response.Write("< script language=javascript>alert('Congratulations, registration was successful!')< /script>");
Response.Write("< script language=javascript>window.parent.frameLeft.location.href='main.html'< /script>");
This solves the problem of ASP.NET framework page jump interruption. In fact, this method is generally used in Asp and PHP.
"window.location.href" and "location.href" are jumps to this page
"parent.location.href" is the previous page jump
"top.location.href" is the outermost page jump
Give an example:
If A, B, C, D are all jsp, D is C's iframe, C is B's iframe, B is A's iframe, if js is written in D
"window.location.href", "location.href": D page jump
"parent.location.href": page C jump
"top.location.href": Page A jump
If there is a form on page D,
<form>: D page jumps after form is submitted
<form target="_blank">: A new page pops up after form is submitted
<form target="_parent">: The C page jumps after form is submitted
<form target="_top"> : Page A jump after form is submitted
Regarding page refresh, the following is written in page D:
"parent.location.reload();": C page refresh (of course, you can also use the opener object of the child window to obtain the parent window's object: window.opener.document.location.reload(); )
"top.location.reload();": Page A refresh