js 中location 的学习

alert(location.hash);// 空alert(location.host);//返回服务器名称和端口号alert(location.hostname);//返回不带端口号的服务器名称alert(location.href);//返回当前加载页面的完整的URLalert(location.toString());//返回当前加载页面的完整的URLalert(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"]);//10//window.location.href="http:www/baidu.com"; //http://localhost:63342/js%E5%AD%A6%E4%B9%A0/www/baidu.com

//这两个属性实则调用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中是否有Flashconsole.log(hasIEPlugin("Flash"));  //false

function 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    }}

//跨浏览器获取innerTextfunction getInnerText(element) {    return (typeof element.textContent == ‘string‘) ? element.textContent : element.innerText;}

//跨浏览器设置innerTextfunction 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");
时间: 2024-07-30 07:27:19

js 中location 的学习的相关文章

JS中模板嵌套学习(代码)

<script src="script/jquery-1.4.2.js"></script>    <script src="script/jsrender.js"></script>    <script id="header" type="text/x-jsrender">        <tr>               <th>序号&

JS中childNodes深入学习

<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> </head> <body> <div id="box"> <div></div> <div></div> <div></div> </div> <script

JS中location.search什么意思

JS中location.search什么意思 设置或获取 网页地址跟在问号后面的部分 当以get方式在url中传递了请求参数时,可以利用location的search属性提取参数的值,下面的代码把参数的名称和对应的值存储在2个数组中. <script>function test(){var url=window.location.search;if(url.indexOf("?")!=-1) {    var str = url.substr(1)     strs = s

JS中Location的使用

一.JS中Location属性 属性 hash 设置或返回从井号 (#) 开始的 URL(锚).如果地址里没有"#",则返回空字符串. host 设置或返回主机名和当前 URL 的端口号. hostname 设置或返回当前 URL 的主机名. href 设置或返回完整的 URL.在浏览器的地址栏上怎么显示它就怎么返回. pathname 设置或返回当前 URL 的路径部分. port 设置或返回当前 URL 的端口号,设置或返回当前 URL 的端口号. protocol 设置或返回当前

js中关于prototype学习(2015年1月5号晚)

prototype在js中为原型,只要是对象都有原型,最高原型为Object. 函数作为一特殊的对象,下面探讨prototype(原型)和function(函数)之间的关系. function A (name){ this.name = name; this.f1= function(){ alert("这是A的对象方法,每个对象都可以调用"+this.name); } } A.fA=function (){ alert("这是类方法,只用类可以调用,对象不可以调用"

5月15日上课笔记-js中 location对象的属性、document对象、js内置对象、Date事件对象、

location的属性: host: 返回当前主机名和端口号 定时函数: setTimeout( ) setInterval() 二.document对象 getElementById(); 根据ID值获取一个DOM对象 getElementsByName(); 根据name属性值获取多个Dom对象 getElementsByTagName(); 根据标签获取多个DOM对象 获取标签体内容 innerHTML 获取input的value值 value 获取下拉框选中的值 value this 代

js中location.href的用法

常用的location.href的几种形式: self.location.href; window.location.href; this.location.href; location.href; parent.location.href; top.location.href; 举例: a.html: <form id="form1" action=""> <div><strong>这是a.html页面<strong>

js中location.search、split()HTML5中localStorage

1. location.search在客户端获取Url参数的方法 location.search是从当前URL的?号开始的字符串 如:http://www.baidu.com/s?wd=baidu&cl=3 它的search就是?wd=baidu&cl=3 如: location.search.substr(1).split("&")[0] 可以返回第一个参数:wd=baidu 如: location.search.split('?')[1] 可以返回所有参数:

JS中Location使用

JS和CSS ,HTML 与PHP之间的一些体会 public function del(){ $o_id=isset($_REQUEST['o_id'])?$_REQUEST['o_id']:''; $ids = isset($_REQUEST['ids'])?$_REQUEST['ids']:''; $model = SF('\\model\\AdminModel'); if(!empty($o_id)){ if( $model->del('bk_order','o_id='.$o_id))