javascript获取url的参数,用于集成搜索问题

来源:百度知道 编辑:UC知道 时间:2024/06/06 05:53:20
以下是HTML集成搜索页go.htm用到的javascrit脚本代码:
function Search(){
var go,q;
var uri=new UriQuery(location.search);
go=String(uri.getQuery('QN')).toLowerCase();
q=String(uri.getQuery('q'));
if('string'==typeof(Search.uri[go])){window.location=Search.uri[go]+q}}
function UriQuery(str){try{this._query=(str||location.search)}catch(ex){throw ex}
this.getQuery=function(name){return UriQuery.getQuery(name,this._query)}}
UriQuery.getQuery=function(name,str){return(new RegExp("(\\?|\\&)"+name+"=([^&]*)").test(str))?RegExp.$2:null};

Search.uri={'google':'http://www.google.cn/search?hl=zh-CN&forid=1&prog=aff&q=','baidu':'http://www.baidu.com/s?ie=gb2312&wd='}

用escape
url="http://www.google.cn/search?q="+escape("美女")

楼上正解。
在页面上用 url="http://www.google.cn/search?msg="+encodeURI("美女");
在服务器端用java.net.URLDecoder.decode(msg,"UTF-8");就可以解决乱码问题。