码迷,mamicode.com
首页 > Windows程序 > 详细

(转)window.location.search的用法

时间:2014-10-22 15:51:32      阅读:227      评论:0      收藏:0      [点我收藏+]

标签:style   http   color   io   ar   java   for   sp   on   

location.search是从当前URL的?号开始的字符串
如:http://www.51js.com/viewthread.php?tid=22720
它的search就是?tid=22720

通过这个函数就可以轻易取到连接后面带的参数,这个可用户父窗口向子窗口传递参数
eg:
Java代码:

function openTable(id){
    var feathers="status=no,width=650px,height=670px,top=0px,menubar=no,resizable=no,scrollbars=yes,toolbar=no,channelmode=no";
    var openWin = window.open("allInfo.html?"+id+","+new Date().getTime(),"declare",feathers);
    openWin.focus();
}

function openTable(id){
    var feathers="status=no,width=650px,height=670px,top=0px,menubar=no,resizable=no,scrollbars=yes,toolbar=no,channelmode=no";
    var openWin = window.open("allInfo.html?"+id+","+new Date().getTime(),"declare",feathers);
    openWin.focus();
}


在allInfo.html页面中如果我们要获取id的值的话,可以这样获得
Java代码

<script type="text/javascript">
    var params= window.location.search;//params:?id,date
    var arr = params.substring(1).split(",");
    var id = arr[0];
</script>

(转)window.location.search的用法

标签:style   http   color   io   ar   java   for   sp   on   

原文地址:http://www.cnblogs.com/wanshutao/p/4043327.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!