alert(location.hash);// 空
alert(location.host);//返回服务器名称和端口号
alert(location.hostname);//返回不带端口号的服务器名称
alert(location.href);//返回当前加载页面的完整的URL
alert(location.toString());//返回当前加载页面的完整的URL
alert(location.pathname);//返回URL的目录和文件名
alert(location.port);//返回URL中指定的端口号。如果URL中不包含端口号,则这个属性返回的空字符串
alert(location.protocol);//返回的协议名称是http 还是https;
alert(location.search);//返回的是查询字符串

查询字符串参数
function getQueryStringArgs(){//取得查询字符串并去掉开头的问号var qs=(location.search.length > 0 ? location.search.substring(1) : "");//console.log(qs);//var str='hello world';//var subStr=str.substring(1); //substring 提取从 indexStart 到 indexEnd(不包括)之间的字符,substring(indexStart,indexEnd);// console.log(subStr) //ello world//var subStr=str.substring(1,0)//console.log(subStr) //h//保存数据的对象//var strs=str.split(" ");//console.log(strs);//["hello", "world"]var args={},//取得每一项items=qs.length ? qs.split("&") : [], // split() 方法通过把字符串分割成子字符串来把一个 String 对象分割成一个字符串数组。item=null,name=null,value=null,i=0;len=items.legth;for(i=0;i<len;i++){item=items[i].split("=");name=decodeURIComponent(item[0]);value=decodeURIComponent(item[1]);if(name.length){args[name]=value;}}return args;
}

假设 查询的字符串是?q=javascript&num=11
var args=getQueryStringArgs();
alert(args["q"]);// javascript
alert(args["num"]);//11

这两个属性实则调用location.assign(URL)方法
window.location="http://www.baidu.com"; //跳转到百度页面
location.href="http://www.baidu.com";//跳转到百度页面

setTimeout(function(){location.replace('http://www.baidu.com');//跳转到百度后,前进和后退的按钮被禁用了location.href="http://www.baidu.com";// 跳转到百度页面,后退的按钮没有被禁用window.location="http://www.baidu.com"; //跳转到百度页面,后退的按钮没有被禁用location.reload();//重新加载 (有可能从缓冲中加载)location.reload(true);//重新加载 (从服务器重新加载);
},1000);

//检查插件 (在IE中无效) 传入一个插件名
function hasPlugin(name){name=name.toLowerCase(); // 全转为小写for(var i=0;i<navigator.plugins.length;i++){if(navigator.plugins[i].name.toLowerCase().indexOf(name)>-1){return true;}}return false;
}
console.log(hasPlugin("Flash"));//true
//检测IE中的插件 传入一个插件名
function hasIEPlugin(name){try{new ActiveXObject(name);return true;} catch(ex){// console.log(ex);return false;}
}
//检测IE中是否有Flash
console.log(hasIEPlugin("Flash"));  //falsefunction hasFlash(){var result=hasPlugin("Flash");if(!result){result=hasIEPlugin("ShockwaveFlash.ShockwaveFlash");console.log(result);}return result;//true
}
console.log(hasFlash());//true
//console.log(hasPlugin('Flash')); //true//console.log(navigator.plugins);  //检测到4个插件
/*for(var i=0;i<navigator.plugins.length;i++){console.log(navigator.plugins[i].name); //Chrome PDF Viewer Shockwave Flash Native Client  Chrome PDF Viewer
}
*/
//var str="hello world";
//console.log(str.toLowerCase());//hello world  字符串toLowerCase() 转换小写
//console.log(str.toUpperCase()); //HELLO WORLD  字符串toUpperCase() 转换大写
//location.href="http://www.baidu.com";
//history.go(-1);
//history.go(1);
//history.go("httt://www.baidu.com");
//history.back();//后退
//0history.forward();//前进

//跨浏览器获取视口大小
function getInner() {if (typeof window.innerWidth != 'undefined') {return {width : window.innerWidth,height : window.innerHeight}} else {return {width : document.documentElement.clientWidth,height : document.documentElement.clientHeight}}
}//跨浏览器获取滚动条位置
function getScroll() {return {top : document.documentElement.scrollTop || document.body.scrollTop,left : document.documentElement.scrollLeft || document.body.scrollLeft}
}//跨浏览器获取innerText
function getInnerText(element) {return (typeof element.textContent == 'string') ? element.textContent : element.innerText;
}//跨浏览器设置innerText
function setInnerText(elememt, text) {if (typeof elememt.textContent == 'string') {elememt.textContent = text;} else {elememt.innerText = text;}
}
//console.log(getInner());
//console.log(getScroll());
//var div=document.getElementsByTagName("div")[0];
//console.log(getInnerText(div));
//setInnerText(div,"abc");


转载于:https://www.cnblogs.com/jifengdehao/p/5684829.html

js 中location 的学习相关推荐

  1. 绒毛动物探测器:通过TensorFlow.js中的迁移学习识别浏览器中的自定义对象

    目录 起点 MobileNet v1体系结构上的迁移学习 修改模型 训练新模式 运行物体识别 终点线 下一步是什么?我们可以检测到脸部吗? 下载TensorFlowJS-Examples-master ...

  2. JS中Location使用详解

    javascript中 location用于获取或设置窗体的URL,并且可以用于解析URL,是BOM中最重要的对象之一,下面我们就来详细探讨下Location对象的使用. javascript中loc ...

  3. JS中location对象使用

    location 地址对象 它描述的是某一个窗口对象所打开的地址.要表示当前窗口的地址,只需要使用"location"就行了:若要表示某一个窗口的地址,就使用"<窗 ...

  4. JS 中 location.href 的用法

    Jsp 中 常用到js来跳转页面; 整理了一下js location.href 的用法 Javascript中的location.href有很多种用法,主要如下: self.location.href ...

  5. JS中location的用法和作用

    window.location 对象所包含的属性: 属性 描述 hash 从井号 (#) 开始的 URL(锚) host 主机名和当前 URL 的端口号 hostname 当前 URL 的主机名 hr ...

  6. 使用TensorFlow.js在浏览器中进行深度学习入门

    目录 设置TensorFlow.js 创建训练数据 检查点 定义神经网络模型 训练AI 测试结果 终点线 内存使用注意事项 下一步是什么?狗和披萨? 下载TensorFlowJS示例-6.1 MB T ...

  7. php中location.reload,js刷新页面location.reload()用法详解

    本文介绍了js刷新页面函数location.reload()的用法,有关js location.reload()函数的例子,有需要的朋友参考下. 在javascript编程中,多使用location. ...

  8. 在浏览器中进行深度学习:TensorFlow.js (四)用基本模型对MNIST数据进行识别

    2019独角兽企业重金招聘Python工程师标准>>> 在了解了TensorflowJS的一些基本模型的后,大家会问,这究竟有什么用呢?我们就用深度学习中被广泛使用的MINST数据集 ...

  9. 关于js中window.location.href、location.href 等如何跳转

    关于js中"window.location.href"."location.href"."parent.location.href".&qu ...

最新文章

  1. 参数整定临界比例度实验_控制算法手记自动整定方法初步
  2. Bitmap类getPixels()方法中参数stride理解
  3. (LeetCode 83)Remove Duplicates from Sorted Lists
  4. 更快的Maven来了,我的天,速度提升了8倍!
  5. MATLAB教程(1) MATLAB 基础知识(3)
  6. 十二届蓝桥杯C++ 1月 中 高级组试题 第4题 病毒繁殖
  7. linux 中断分上下部分的原因
  8. 要兼容ie时注意事项
  9. DPDK初始化分析(五)
  10. 微信分享出错问题,MicroMsg.SDK.WXMediaMessage: checkArgs fail, thumbData is invalid
  11. Excel 快速填充序号
  12. 【BP预测】基于BP神经网络实现混凝土强度预测含Matlab源码
  13. 大数据框架之Spark详解
  14. 十二平均律的数学描述
  15. 微信公众号网页开发-Vue项目坑点分析
  16. 期货市场技术分析读后感
  17. kex_exchange_identification: Connection closed by remote host
  18. Python分析00-90后的微信昵称,发现如下规律!
  19. 遇人不淑之逗比程序员
  20. 第29题:link与@import的区别

热门文章

  1. Python爬虫开发:正则表达式re的使用
  2. Python Django 表单类Form(py代码画form表单仅渲染页面)
  3. Python Django 自定义Manager(重写父类方法实现自定义逻辑)
  4. kibana操作elasticsearch:匹配查询(match)
  5. 类变量与实例变量辨析
  6. 苹果电脑通过密钥对的方式登录linux系统
  7. 多线程下载的原理和基本用法
  8. linux下的几种进程间通信方式的特点
  9. java引用其他类的数据头文件_Java 实现数据表与简单Java类映射转换
  10. 烽火传递(dp+单调队列)