window.location.href js语句location.href怎么让它到新窗口打开
朋友们,你是否曾想过深入了解window.location.href和js语句location.href怎么让它到新窗口打开的内涵?在本文中,我将为你详细解析这两个话题,希望能给你带来全新的视角和思考。
window.location.href的用法
javascript中的 location.href有很多种用法,主要如下:
self.location.rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" href="/url"当前页面打开
location.rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" href="/url"当前页面打开
windows.location.rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" href="/url"当前页面打开,前面三个用法相同
this.location.rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" href="/url"当前页面打开
parent.location.rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" href="/url"在父页面打开新页面
top.location.rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" href="/url"在顶层页面打开新页面
location.open("/url");打开一个新的窗口页
如果页面中自定义了 frame,那么可将 parent self top换为自定义 frame的名称,效果是在 frame窗口打开 url地址
window.location.href 和window.location的区别
window.location是页面的位置对象,window.location.href是 location的一个属性值,并且它是location的默认属性就是说对window.location直接赋值一个url实际上就是对window.location.href赋值。location对象除了有href属性外还有很多其他属性和方法,而href就是一个字符串
只不过修改location的href会触发浏览器加载 href所指向的url
因此不存在前者速度比后者快的。
btw:你判断前者比后者快的依据是什么?事实上,加载同一个url的速度不一定每次都一样,这个受当时的网络状况,页面内容是否已经有被缓存等有关。
js语句location.href怎么让它到新窗口打开
用 window.open
location.href只能引导当前页的转向
window.open('OPK://Messages/?uid=0&target='+s_price);
这不是回到矛和盾的问题了吗。弹出与拦截之间,就是个痛。
查了一下,有可以不被拦截人处理办法,但太复杂,可以用一个折中办法来提示
var win= window.open('OPK://Messages/?uid=0&target='+s_price);
if(win== null){
alert('新窗口看起来是被一个弹出窗口拦截程序所阻挡。如果想打开新窗口,我们建议您将本站点加入到这个拦截程序设定的允许弹出名单中。有的弹出窗口拦截程序允许在长按Ctrl键时可以打开新窗口。');
}
window.location.href 和self.location的区别
一、指代不同
1、window.location.href:返回当前窗口在浏览器中就是完整的地址。
2、self.location:返回指定窗口在浏览器中就是完整的地址。
二、作用不同
1、window.location.href:URL的端口部分。如果采用默认的80端口(update:即使添加了:80),那么返回值并不是默认的80而是空字符。
2、self.location:查询(参数)部分。除了给动态语言赋值以外,我们同样可以给静态页面,并使用javascript来获得相信应的参数值。
三、用法不同
1、window.location.href:除了设置 location或 location.href用完整的 URL替换当前的 URL之外,还可以修改部分 URL,只需要给 Location对象的其他属性赋值即可。
2、self.location:表示的却是浏览器当前显示的文档的 URL(或位置)。但是 Location对象所能做的远远不止这些,还能控制浏览器显示的文档的位置。
参考资料来源:百度百科-Location对象
参考资料来源:百度百科-window.location
文章到此结束,希望我们对于window.location.href和js语句location.href怎么让它到新窗口打开的问题能够给您带来一些启发和解决方案。如果您需要更多信息或者有其他问题,请随时联系我们。