详解location.href几种用法的区别

详解location.href几种用法的区别

你。 提交于 2019-11-27 01:00:55
一:提出问题 使用js的同学一定知道js的location.href的作用是什么,但是在js中关于location.href的用法究竟有哪几种,究竟有哪些区别,估计很多人都不知道了。 blog已经迁移到 这里 了,有更多文章,欢迎大家访问。 二:常见的几种形式 目前在开发中经常要用到的几种形式有: self.location.href; window.location.href; this.location.href; location.href; parent.location.href; top.location.href; 经常见到的大概有以上几种形式。 三:代码部分 那么,这几种形式的跳转究竟有什么区别呢? 直接讲定义,你肯定不会理解透彻,下面我来贴四个html代码,用实际的例子讲解。 a.html: <form id="form1" action=""> <div><strong>这是a.html页面<strong> <iframe src="b.html" width="500px" height="300px"></iframe> </strong></strong></div> </form> <pre> b.html: <span>这是b.html</span><span id="span1"></span><br /> <iframe src="c.html"