Detailed explanation of location. href address redirection in javascript

Source: Internet
Author: User

Location. href has many usage methods in js mainly to control page navigation or jump to the upper-level framework page. Below I have sorted out the location for you. the href address jump parameter introduction is helpful to you.

Location. href in javascript has many usage methods, mainly as follows.
 
Top. location. href = "url" opens the url on the top-level page (jump out of the Framework)

Self. location. href = "url" only opens the url address on this page

Parent. location. href = "url" opens the Url address in the parent window.

This. location. href = "url" is used in the same way as self.

Location. href = "/url" the current page opens the URL page

Windows. location. href = "/url": the current page opens the URL page. The previous three operations are the same.


If the frame is customized on the page, you can replace parent self top with the name of the custom frame to open the url address in the frame window.

In addition, window. location. href = window. location. href; and window. location. Reload () both refresh the current page. The difference is whether data is submitted. When data is submitted, window. location. Reload () will prompt whether to submit. window. location. href = window. location. href; then the data is submitted to the specified url.

The location page jumps to js as follows:

The Code is as follows: Copy code

// Simple jump
Function gotoPage (url)
{
// Eg. var url = "newsview.html? Catalogid = "+ catalogID +" & pageid = "+ pageid;
Window. location = url;
}
// Upgrade the location usage to pass parameters for a single page
Function goto_catalog (iCat)
{
If (iCat <= 0)
{
Top. location = "../index. aspx"; // top
}
Else
{
Window. location = ".../newsCat. aspx? Catid = "+ iCat;
}
}
// Jump to the page of the specified framework. Both methods are available.
Function goto_iframe (url)
{
Parent. mainFrame. location = ".../index. aspx ";//
// Parent.doc ument. getElementById ("mainFrame"). src = ".../index. aspx"; // use dom to change page // At the same time, I added dom writing.
}
// Jump to the page for the specified framework, because parent. iframename. location = ".. /index. aspx "; the method cannot be implemented, mainly" parent. iframename in iframename is set as a node by default in js, but the passed parameters cannot be converted. Therefore, dom is used to implement the frame jump page for passing two parameters, I hope that this old man will be enlightened!
Function goto_iframe (iframename, url)
{
Parent.doc ument. getElementById (iframename). src = ".../index. aspx"; // use dom to change page by iframeName

//}
// Return to the home page
Function gohome ()
{
Top. location = "/index. aspx ";
}
</Script>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.