星期六, 八月 07, 2004

Google如何利用URLEncoder来处理事情。

红色的注释encodeURIComponent是关键。

<html><head><meta HTTP-EQUIV="content-type" CONTENT="text/html; charset=UTF-8">
<script>
function qs()
{
el=document.mainform.chinese;
if (window.RegExp && window.encodeURIComponent)
{
var qe=encodeURIComponent(el.value);
prompt("Transmit",qe);
window.location.href="http://www.google.com/search?q="+qe+"&sourceid=firefox&start=0&start=0&ie=utf-8&oe=utf-8";
}
}
// -->
</script>

<body>
<form name="mainform">
<input type="text" name="chinese"><input type="button" value="Trasmition" onclick="qs()">
</form>