转:关于js中"window.location."、"location."、"parent.location."、"top.location用法

本文介绍了使用JavaScript进行页面跳转及刷新的方法,包括window.location.href、parent.location.href及top.location.href的区别,并提供了不同场景下的具体应用实例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

转自

http://www.cnblogs.com/yugen/archive/2010/08/03/1791560.html

window.location.href"、"location.href"是本页面跳转
"parent.location.href"是上一层页面跳转
"top.location.href"是最外层的页面跳转

举例说明:
如果A,B,C,D都是aspx,D是C的iframe,C是B的iframe,B是A的iframe,如果D中js这样写
"window.location.href"、"location.href":D页面跳转
"parent.location.href":C页面跳转
"top.location.href":A页面跳转
如果D页面中有form的话,
<form>:  form提交后D页面跳转
<form target="_blank">:  form提交后弹出新页面
<form target="_parent">:  form提交后C页面跳转
<form target="_top"> :  form提交后A页面跳转

关于页面刷新,D 页面中这样写:

"parent.location.reload();": C页面刷新  (当然,也可以使用子窗口的 opener 对象来获得父窗口的对象:window.opener.document.location.reload(); )
"top.location.reload();": A页面刷新
<body style=&quot;zoom: 1;&quot; class=&quot;x-body x-webkit x-chrome&quot; id=&quot;ext-gen1049&quot;> <div id=&quot;cardFocus&quot; tabindex=&quot;0&quot; aria-label=&quot;正文&quot; role=&quot;option&quot;></div> <input type=&quot;hidden&quot; id=&quot;supportAiBrainMap&quot; value=&quot;false&quot;> <input type=&quot;hidden&quot; id=&quot;useBigModelAnalysis&quot; value=&quot;true&quot;> <input type=&quot;hidden&quot; id=&quot;aiVideoInterpret&quot; value=&quot;0&quot;> <input type=&quot;hidden&quot; id=&quot;curCourseId&quot; value=&quot;241284601&quot;> <input type=&quot;hidden&quot; id=&quot;ut&quot; value=&quot;s&quot;> <input type=&quot;hidden&quot; id=&quot;clazzId&quot; value=&quot;116833926&quot;> <div class=&quot;wrap &quot; style=&quot;min-width: 846px; padding: 30px 80px;&quot;> <div class=&quot;ans-cc&quot;> <p class=&quot;editor-iframe&quot; draggable=&quot;true&quot; tabindex=&quot;-1&quot;><div class=&quot;ans-attach-ct&quot; id=&quot;ext-gen1050&quot;><div class=&quot;ans-job-icon ans-job-icon-clear &quot; tabindex=&quot;0&quot; aria-label=&quot;任务点未完成&quot; role=&quot;option&quot; id=&quot;ext-gen1051&quot;><i></i></div><iframe src=&quot;/ananas/modules/video/index.html?v=2025-0317-1842&quot; class=&quot;ans-attach-online ans-insertvideo-online&quot; data=&quot;{&quot;jobid&quot;:&quot;1709289392246740&quot;,&quot;rt&quot;:&quot;0.9&quot;,&quot;size&quot;:273740041,&quot;fastforward&quot;:&quot;true&quot;,&quot;hsize&quot;:&quot;261.06 MB&quot;,&quot;name&quot;:&quot;3\u7269\u8d28\u53ca\u5176\u5b58\u5728\u65b9\u5f0f.mp4&quot;,&quot;mid&quot;:&quot;5720161048601709289391748&quot;,&quot;type&quot;:&quot;.mp4&quot;,&quot;doublespeed&quot;:1,&quot;objectid&quot;:&quot;51b604b85ec5206617898349754fff10&quot;,&quot;_jobid&quot;:&quot;1709289392246740&quot;}&quot; objectid=&quot;51b604b85ec5206617898349754fff10&quot; fastforward=&quot;true&quot; switchwindow=&quot;&quot; vbegin=&quot;&quot; vend=&quot;&quot; mid=&quot;5720161048601709289391748&quot; jobid=&quot;1709289392246740&quot; frameborder=&quot;0&quot; scrolling=&quot;no&quot; allowfullscreen=&quot;true&quot; webkitallowfullscreen=&quot;true&quot; mozallowfullscreen=&quot;true&quot; style=&quot;height: 540px;&quot;></iframe><div id=&quot;topicList&quot; style=&quot;border:none;&quot;><div id=&quot;topicType&quot;></div><div id=&quot;topicContent&quot;></div></div></div></p> </div> </div> <script> (function(){ mArg = &quot;&quot;; try{ mArg = {&quot;hiddenConfig&quot;:false,&quot;isMirror&quot;:false,&quot;attachments&quot;:[{&quot;otherInfo&quot;:&quot;nodeId_831615518-cpi_447785969-rt_0.9-ds_1-ff_1-be_0_0-
最新发布
03-27
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值