系統公告
訂閱本部落格
搜尋站內文章
最新發表文章
最新的回應
- 大頭:
連線失敗 ... - sfl23430:
部落格熱潮正在全世界發... - 軟體邦 http://software.sopili.net/:
本篇文章引用於此 ... - chinashit:
中國的睡到一半小心著火... - 支持民族工业:
我们中国也有太空舱式卧...
好時光貼曆
文章分類
- 資訊科技 (5)
- 程式設計 (6)
- 趣味搞笑 (2)
- 狗狗相關 (4)
- 社會關懷 (0)
- 沒有項目
- 其他 (2)
即時留言版
網路串連
誰來我家
贊助商
其它資訊
本部落所刊登之內容,皆由作者個人所提供,不代表 yam天空部落 本身立場。
February 27, 2007
某天,因為專案需求,到網路上尋找是否可以透過 JavaScript 直接剖析 HTTP 的請求參數。
真的是太神奇了, JavaScript 竟然真的可以做到這種程度,趕緊跟大家分享一下。
它的做法是這樣子的:
宣告一個全域變數,把網域的參數存起來
宣告一個 getParameter 函數, 負責取得特定名稱的參數內容
接下來,只要簡單呼叫 getParameter 並傳入參數名稱,就可以取得內容了。
<script language="Javascript">
var queryString = window.top.location.search.substring(1);
function getParameter ( queryString, parameterName ) {
// Add "=" to the parameter name (i.e. parameterName=value)
var parameterName = parameterName + "=";
if ( queryString.length > 0 ) {
// Find the beginning of the string
begin = queryString.indexOf ( parameterName );
// If the parameter name is not found, skip it, otherwise return the value
if ( begin != -1 ) {
// Add the length (integer) to the beginning
begin += parameterName.length;
// Multiple parameters are separated by the "&" sign
end = queryString.indexOf ( "&" , begin );
if ( end == -1 ) {
end = queryString.length
}
// Return the string
return unescape ( queryString.substring ( begin, end ) );
}
// Return "null" if no parameter has been found
return "null";
}
}
</script>
按下按鈕後就看到結果了
真的是太神奇了, JavaScript 竟然真的可以做到這種程度,趕緊跟大家分享一下。
它的做法是這樣子的:
宣告一個全域變數,把網域的參數存起來
宣告一個 getParameter 函數, 負責取得特定名稱的參數內容
接下來,只要簡單呼叫 getParameter 並傳入參數名稱,就可以取得內容了。
<script language="Javascript">
var queryString = window.top.location.search.substring(1);
function getParameter ( queryString, parameterName ) {
// Add "=" to the parameter name (i.e. parameterName=value)
var parameterName = parameterName + "=";
if ( queryString.length > 0 ) {
// Find the beginning of the string
begin = queryString.indexOf ( parameterName );
// If the parameter name is not found, skip it, otherwise return the value
if ( begin != -1 ) {
// Add the length (integer) to the beginning
begin += parameterName.length;
// Multiple parameters are separated by the "&" sign
end = queryString.indexOf ( "&" , begin );
if ( end == -1 ) {
end = queryString.length
}
// Return the string
return unescape ( queryString.substring ( begin, end ) );
}
// Return "null" if no parameter has been found
return "null";
}
}
</script>
上面的 Script 照抄就好了, 可以加下面這行做為測試
<input type=button value="測試按鈕" onclick="alert(getParameter(queryString, 'name'));">
按下按鈕後就看到結果了
2.
sfl23430
於 2009-06-22 16:00:25 留言 |
1.
GDI夢想域名網路推廣中心
http://www.playgamenow.ws/
1.頂級域名網址
2.專屬域名電子信箱
3.大容量網頁空間與流量
4.網頁設計小幫手
5.全球銷售權:
以上服務能夠純粹在電腦網路上交易
可不受工作時間工作地點影響
沒有進出貨等空間問題
能完全在家工作
歡迎參考
http://www.playgamenow.ws/
1.頂級域名網址
2.專屬域名電子信箱
3.大容量網頁空間與流量
4.網頁設計小幫手
5.全球銷售權:
以上服務能夠純粹在電腦網路上交易
可不受工作時間工作地點影響
沒有進出貨等空間問題
能完全在家工作
歡迎參考
playgamenow
於 2008-07-21 16:28:42 留言 |
yam天空部落 建置維護 © 1999~2009 webs-tv inc. All Rights Reserved.






甜蜜的家



































想擁有自已的免費空間、終身網址及部落格嗎??
如何善用自已的部落格為自已帶來額外的收入呢??
搶先別人一步~快來註冊自已喜愛的網址!!
申請方式請參考http://www.itochu.ws
gigi8877@hotmail.com