Using code to open hyperlinks in javascript: Usages and instances of location.href

Source: Internet
Author: User

*.location.href usage:

top.location.href= "url" opens the URL on the top-level page (out of the frame)

self.location.href= "url" opens URL address only on this page

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

this.location.href= the "url" usage is consistent with the use of self

if (top.location = = self.location) Determines whether the current location is the top level to prevent frame references

If you have a custom frame on the page, you can also change parent self top to the name of the custom frame

The effect is to open the URL address in the Custom frame window

JavaScript frame Refresh

Reference:

--------------------------------------------------------------------------------

This is a simple example:

Here's the top.htm code

<script language=javascript>

Function Rs () {

parent.left.location.href= "Top.htm"

parent.bot.location.href= "Top.htm"

}

</script>

<input Type=button name=name value= "Ksdj" Onclick=rs ();>

Here is a random file name of the HTM file:

<frameset cols= "150,*" >

<frame src= "Left.htm" name=left>

<frameset rows= "150,*" >

<frame src= "Top.htm" name=top>

<frame src= "bot.htm" name=bot>

</FRAMESET>

</FRAMESET>

You try it yourself, I think you want to be the effect of this!

--------------------------------------------------------------------------------

I quote a reply from the man upstairs and help explain it.

Here's the top.htm code

<script language=javascript>

Function Rs () {

parent.left.location.href= "top.htm"//partent refers to the parent page, which is the outermost frame page, and left has to be the always object of the left page, and href is an attribute of the Location object, which determines the URL address of the left. So here's the address you need to give this parent.left.

parent.bot.location.href= "top.htm"//The meaning of this sentence is similar to the above.

}//function is complete, the update is implemented at the same time for two URLs!

</script>

<input Type=button name=name value= "Ksdj" Onclick=rs ();>

Here is a random file name of the HTM file:

<frameset cols= "150,*" >

<frame src= "left.htm" name=left> >//To this left.htm defined a name called Left

<frameset rows= "150,*" >

<frame src= "top.htm" name=top>//to this top.htm defined a name called top

<frame src= "bot.htm" name=bot>//to this bot.htm defined a name called bot

</FRAMESET>

</FRAMESET>

The Location property of the Window object contains the address (URL) information for the current page, and you can change this property value directly to a new address (URL):

window.location = "http://www.yahoo.com/";

Or

Location = "http://www.yahoo.com/";

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/webkf/script/

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.