JS Control Frame page Jump Top.location.herf = "url"

Source: Internet
Author: User

What's the difference between Top.location.href and localtion.href?

top.location.href= "url" opens the URL in the top-level page (out of the frame) self.location.href= "url" opens the URL address only on this page Parent.locati on.href= "url" opens the URL address in the parent window this.location.href= "url" usage consistent with the use of self if (top.location = = self.location) Judging current L Ocation whether a frame reference is a top level if there is a custom frame in the page, you can also change the parent self top to a custom frame name effect is to open the URL address in the Custom frame window

This may be used in practice

if (top!== self) {top.location.href = Location.href; Prohibit frame reference

Here is an example from the Internet, not very intuitive, I added the above three lines of code, you can first remove, plus, look at the effect, it is clear that the following is the Top.htm code <script language=javascript> function rs () {

if (top!== self) {top.location.href = Location.href; } parent.left.location.href= "Top.htm" parent.bot.location.href= "top.htm"} </script> < input Type=button name =name value= "Ksdj" Onclick=rs ();>
The following is an HTM file with a random file name: <frameset cols= "150,*" > < FRAME src= "left.htm" Name=left> < FRAMESET rows= "150,*" > & Lt Frame src= "top.htm" Name=top> < frame src= "bot.htm" Name=bot> </frameset> </frameset> you try it yourself, I think you can. Can be such an effect!

Top represents the main window, location represents the current window, if your file has only one frame, no iframe and Frmaeset, then it is exactly the same, no difference.

Top.location is opening a new page in the top-level frame window.location is opening a new page in the current frame parent.location opens the URL address in the current window's parent window top represents the main window, location represents the current window, If your file has only one frame, no iframe and Frmaeset, then it's exactly the same, no difference.

JS Control Frame page Jump Top.location.herf = "url"

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.