javascript解析urlパラメータ
2071 ワード
1.ジャンプ前ページ:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<a href="target.html?id=aa&str=test&targetUrl=http://www.sina.com" > </a>
</body>
</html>
2.ジャンプ後のページ:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta charset="utf-8"/>
<title>vao365.com</title>
</head>
<body>
<iframe id="container" src="" frameborder="no" scrolling="auto" width="100%" height="100%"
onload="document.all['container'].style.height=container.document.body.scrollHeight;document.all['container'].style.height=container.document.body.scrollHeight;">
</iframe>
<script type="text/javascript">
function QueryString()
{
var name,value,i;
var str=location.href;
var num=str.indexOf("?")
str=str.substr(num+1);
var arrtmp=str.split("&");
for(i=0;i < arrtmp.length;i++){
num=arrtmp[i].indexOf("=");
if(num>0){
name=arrtmp[i].substring(0,num);
value=arrtmp[i].substr(num+1);
this[name]=value;
}
}
}
//--------------------------------------
// :
var Request=new QueryString();
id=Request["id"]
str=Request["str"]
document.write(id);
document.write(str);
targetUrl = decodeURI(Request["targetUrl"]);
document.getElementById('container').src = targetUrl;
</script>
</body>
</html>