The use of of dynamic output jump for window.location.href
- 2020-03-30 03:41:33
- OfStack
Location.href in javascript can be used in a number of ways, 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 USES are the same.
This.location.href ="/url" the current page opens the url page
Parent.location.href ="/url" opens a new page on the parent page
Top.location.href ="/url" opens a new page on the top-level page
If you have a custom frame on the page, you can change parent self top to the name of the custom frame by opening the url address in the frame window
In addition, the window. The location. Href = window. The location. The href; Window.location.reload () and both refresh the current page. The difference is whether data is submitted. When data is submitted, window.location.reload () will prompt whether or not to submit, window.location.href=window.location.href; Is to submit the data to the specified url
When writing ASP.Net programs, we often encounter the problem of redirection. We often use response.redirect to do ASP.Net frame page Redirect.
Response.Write("< script>alert(' Congratulations! Registration is successful! ');< /script>");
Response.Redirect("main.html");
At this point our prompt content does not come out, and response.redirect ("main.html"); It doesn't make any difference.
Now let's experiment with the following code:
ASP.NET framework page jump another implementation
Response.Write("< script language=javascript>alert(' Congratulations! Registration is successful! ')< /script>");
Response.Write("< script language=javascript>window.location.href='main.html'< /script>");
This is to achieve our requirements, after the prompt, jump to the page.
Most importantly, the window.location.href statement enables the page of one framework to refresh the page of another after executing server-side code (response.redirect cannot be reached, at least not by me) :
For example, there are two frames in the index.htm page, which are frameLeft and frameRight respectively. After executing the server-side code in the frameRight page, the page in frameLeft is refreshed.
Previously the most common is after registration, automatically refresh the login box, let the login box into the login page, as long as the code after the successful registration of a paragraph, that can achieve the refresh of another frame page. The code is as follows:
Response.Write("< script language=javascript>alert(' Congratulations! Registration is successful! ')< /script>");
Response.Write("< script language=javascript>window.parent.frameLeft.location.href='main.html'< /script>");
This solves the problem of ASP.NET frame page jump interrupts. In fact, asp, PHP generally use this way.
"Window.location.href", "location.href" is the page to jump to
"Parent.location.href" is a page jump from the previous level
"Top.location.href" is the outermost page jump
Examples:
If A,B,C, and D are all JSPS,D is the iframe of C, C is the iframe of B, and B is the iframe of A, if js is written like this in D
"Window.location.href", "location.href" : D page skip
"Parent.location.href" : C page jump
"Top.location.href" : page A to jump
If there's a form in D,
< Form> : page D jumps after the form is submitted
< The form target = "_blank" > : a new page pops up after the form is submitted
< The form target = "_parent" > : page C jumps after the form is submitted
< The form target = "_top" > : page A jumps after the form is submitted
For page refresh, page D reads:
"The parent. The location. Reload ();" : C page refresh (of course, can also use the child window opener for the parent window object: window. The opener. The document. The location. Reload (); )
"Top. Location. Reload ();" : A page refresh