用js获取当前路由信息的方法

1,设置或获取对象指定的文件名或路径。

alert(window.location.pathname)

2,设置或获取整个 URL 为字符串。

alert(window.location.href);

3,设置或获取与 URL 关联的端口号码。

alert(window.location.port)

4,设置或获取 URL 的协议部分。

alert(window.location.protocol)

5,设置或获取 href 属性中在井号“#”后面的分段。

alert(window.location.hash)

6,设置或获取 location 或 URL 的 hostname 和 port 号码。

alert(window.location.host)

7,设置或获取 href 属性中跟在问号后面的部分。

alert(window.location.search)

8,获取变量的值(截取等号后面的部分)

var url = window.location.search;

//    alert(url.length);

//    alert(url.lastIndexOf(‘=‘));

var loc = url.substring(url.lastIndexOf(‘=‘)+1, url.length);

9,用来得到当前网页的域名

var domain = document.domain;

原文地址:https://www.cnblogs.com/qhantime/p/11679282.html

时间: 2024-08-30 03:41:08

用js获取当前路由信息的方法的相关文章

原生js获取css中class的方法

function getByClass( className, context) { var context = context || document; if( context.getElementsByClassName) { return context.getElementsByClassName(className); } var nodes = context.getElementsByTagName("*"); ret=[]; for( var i=0; i<nod

JS获取IE浏览器信息类型、版本、语言等

分享下JS获取IE浏览器信息包括类型.版本.语言等的实例. 代码: <html> <head> <title>JS完整获取IE浏览器信息--www.jbxue.com</title> </head> <body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"> <table

Request获取url各种信息的方法

1.Request获取url各种信息的方法 测试的url地址:http://www.test.com/testweb/default.aspx, 结果如下: Request.ApplicationPath: /testweb Request.CurrentExecutionFilePath: /testweb/default.aspx Request.FilePath: /testweb/default.aspx Request.Path: /testweb/default.aspx Reque

PHP获取http头信息和CI中获取HTTP头信息的方法

CI中获取HTTP头信息的方法: $this->input->request_headers() 在不支持apache_request_headers()的非Apache环境非常有用.返回请求头(header)数组. $headers = $this->input->request_headers(); ------------------------------------------------------------------------------------------

获取当前年月日...信息的方法,获取请求的ip地址,由于数据库中是time格式,所以要获取时分秒的格式

1.获取当前年月日...信息的方法 1 public class CommonDate { 2 3 public final String year = String.valueOf(Calendar.getInstance().get(Calendar.YEAR)); 4 public final String month = String.valueOf(Calendar.getInstance().get(Calendar.MONTH)+1); 5 public final String

JS获取DOM的几种方法

JS获取DOM和几种方法 通过ID获取(getElementById) 通过name属性(getElementsByName) 通过标签名(getElementsByTagName) 通过类名(getElementsByClassName) 获取html的方法(document.documentElement) 获取body的方法(document.body) 通过选择器获取一个元素(querySelector) 通过选择器获取一组元素(querySelectorAll) 下面依次讲解:1.通过

JS获取HTML DOM元素的方法

在JS中获取元素的方法有很多,可以根据实际需要选择合适的方法 一.JS获取元素的方法 1)根据id获取标签元素 var div1=document.getElementById("div1"); 2)根据标签名获取标签列表 var divs=document.getElementsByTagName("div") 3)根据className获取标签列表 var div0=document.getElementsByClassName("div0"

JS获取各种浏览器窗口大小的方法

常用:JS 获取浏览器窗口大小 // 获取窗口宽度 if (window.innerWidth) winWidth = window.innerWidth; else if ((document.body) && (document.body.clientWidth)) winWidth = document.body.clientWidth; // 获取窗口高度 if (window.innerHeight) winHeight = window.innerHeight; else if

JS获取客户端计算机硬件信息与系统信息大全

<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script> var info = allinfo(); document.write(info); var locator = new ActiveXObject ("WbemScripting.SWbemLocator");