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"