几种js获取url及参数, 并分析url的任意部分 29 May 2010 9:11 Saturday by 小屋 浏览(2772)

 

 

1.获取URL
获取url方法,直接用location就可以了,window.location或window.loation.href也可以。

  1. <script language="javascript"> 
  2. var t1=location
  3. var t2=window.location
  4. var t3=window.location.href; 
  5. document.write("location="+t1+"<br />"+"window.location="+t2+"<br />"+"window.location.href="+t3); 
  6. </script> 

2.分析URL
运用location获取的url属性为object,要对其进行字符串" title="字符串">字符串的分析操作,需要先将其转换为字符串" title="字符串">字符串。

  1. <script language="javascript" type="text/javascript"> 
  2. var t1=location
  3. var t2=window.location
  4. var t3=window.location.href; 
  5. document.write("location型为: "+typeof(t1)+"<br />"+"window.location型为: "+typeof(t2)+"<br />"+"window.location.href型为: "+typeof(t3)); 
  6. </script> 

location进行处理,首先将其转换为字符串" title="字符串">字符串,用函数toString(

阅读全文>>