1,window.location方法后还还可以带href,search等参数
以下是参数介绍:
location对象 含有当前URL的信息. 属性 href 整个URL字符串.
protocol 含有URL第一部分的字符串,如http:
host 包含有URL中主机名:端口号部分的字符串.如//www.cenpok.net/server/
hostname 包含URL中主机名的字符串.如http://www.cenpok.net ;
port 包含URL中可能存在的端口号字符串.
pathname URL中"/"以后的部分.如~list/index.htm
hash "#"号(CGI参数)之后的字符串.
search "?"号(CGI参数)之后的字符串.
2,例子
(1),pathname,search,href,是比较常用的几个参数下面就举一个这三个参数的例子。
假如页面地址是:http://localhost/test/test.htm?id=1
<html> <head> </head> <body> <script languge=javascript> alert(window.location.pathname); --返回 /test/test.htm alert(window.location.search); --返回 ?id=1 alert(window.location.href); --返回 http://localhost/test/test.htm?id=1 </script> </body> </html>
(2),下面就举一个比较完整的例子
地址:http://www.111cn.net :80/fisker/post/0703/window.location.html?ver=1.0&id=6#imhere
var data=window.location.href ;
输出值:console.log(data)=http://www.111cn.net :80/fisker/post/0703/window.location.html?ver=1.0&id=6#imhere
var data=,window.location.protocol
输出值:console.log(data)=http:
var data=,window.location.host
输出值:console.log(data)=www.111cn.net
var data=window.location.port ;
URL 的端口部分
如果采用默认的80端口(update:即使添加了:80),那么返回值并不是默认的80而是空字符
输出值:console.log(data)=""
var data=window.location.pathname ;
输出值:console.log(data)=/fisker/post/0703/window.location.html
var data=window.location.search;
输出值:console.log(data)=?ver=1.0&id=6
var data=window.location.hash
输出值:console.log(data)=#imhere
相关推荐
window.location.href页面跳转的用法(区别于redirect)
javascript 打开页面window.location和window.open的区别.docx
NULL 博文链接:https://hugang357.iteye.com/blog/1833003
JavaScript中Window.open参数详解 1、最基本的弹出窗口代码 2、经过设置后的弹出窗口 3、用函数控制弹出窗口 4、同时弹出2个窗口 5、主窗口打开文件1.htm,同时弹出小窗口page.html ...
javascript中window.confirm这个方法很好用,可以弹出一个确认对话框我们之所以弹出这个对话框,可能就是因为该操作很危险,所以要用户确认。但如果默认选择”确定”,则可能违背了这个原则。 另外,confirm对话框的...
主要讲解了如何利用window.open打开新窗口,和打开新窗口时的一些参数的设置,很实用的。
详解js location.href和window.open的几种用法和区别.docx
window.open使用方法以及参数说明一、window.open()支持环境: JavaScript1.0+/JScript1.0+/Nav2+/IE3+/Opera3+ 二、基本语法: window.open(pageURL,name,parameters) 其中: pageURL 为子窗口路径 name 为子窗口...
window.open参数详解,这是js中新建页面时常用到的属性及方法
window.open参数详解.txt
本文较为详细的分析了JavaScript中window.open用法。分享给大家供大家参考。具体如下: 代码如下:[removed] window.open (‘page.html’, ‘newwindow’, ‘height=100, width=400, top=0, left=0, toolbar=no, ...
IE9下使用window.open时需要注意name参数值不能有”-“出现,否则会出现脚本错误,IE9以及版本测试没有问题 window.open(URL,name,specs,replace) 参数 说明 URL 可选。打开指定的页面的URL。如果没有指定URL,...
self.location.href;//当前页面打开URL页面 [removed].href;//当前页面打开URL页面 this.location.href;//当前页面打开URL页面 location.href;// 当前页面打开URL页面 parent.location.href;//在父页面打开新...
对window.open进行封装, 使其更好用, 且更兼容, 很多人说window.open不兼容,其实不是, 因为不能直接执行, 必须通过用户手动触发才行;看代码: 代码如下 var openWindow = function(url, options) { var str = ""; ...
html和js通过window.print()实现调用浏览器打印带背景图片和生成二维码的文件功能;直接下载可用
js中window.open()的所有参数详细解析.docx
JavaScript_window.setTimeout()_的详细用法
windows.open这个是JavaScript函数,但是在应用起来的时候总会遇到比较多的麻烦,因为参数非常多,用法也非常的多
window.open()参数大全,window.open()参数大全,window.open()参数大全。
获得当前页面的url ... //获取url中"?"符后的字串 document.referrer 获取来路的url,相当于php的$_SERVER['HTTP_REFERER']。 encodeURIComponent() 对url进行转定义,相当于php的urlencode()函数。