2014年2月26日 星期三

指定網頁編碼

需求 :

發送的網頁是asp ,編碼big5  ,網址傳值,其中傳送的值有中文字

接收的網頁是asp.net,預設編碼utf-8,Request到的值是亂碼


我的解法是在web.config

  <system.web>
    <globalization requestEncoding="big5" responseEncoding="big5"/>


完畢。


==============================
以下方法自行轉換utf8 和 big5

ASP.NET撰寫 utf8網頁
1. HTML Head
<meta http-equiv="content-type" content="text/html; charset=UTF-8">

2. ASP.NET Code
Session.CodePage=65001
Response.CharSet="UFT8"

//Response.Charset = "BIG5";
//Session.CodePage = 950

3. 將 ASPX 利用編碼的方式儲存,建議使用 UTF-8  有簽章 (CodePage 65001)

4. 存放在 SQL Server 欄位必須使用 nchar / nvarchar ,Insert 時必須使用大寫 N

5. IE 測試時請先關閉「自動編碼」




ASP撰寫 utf8網頁
1.HTML Head
<meta http-equiv="Content-Type" content="text/html; charset=utf8">
最好寫在<title>前面 (For IE6 bug)

2.要用記事本另存指定編碼為utf8
這樣才算完整的utf8網頁




2014年2月12日 星期三

[Javascript]在搜尋輸入框輸入字串,按ENTER即送出查詢


龍偷內兜搜尋引擎

在搜尋輸入框輸入字串,按ENTER即送出查詢。


<INPUT type="text" name="strQuery" id="strQuery" style="font-size:

9pt;HEIGHT:17PX;width:110px; background-color: #ffffff; border: 1 solid #FF9900" value="請

輸入關鍵字" accesskey="S" onFocus="javascript:if(value=='請輸入關鍵字'){value='';}"

onKeyPress="javascript:if(event.keyCode == 13){search(this,event)}">

<a href="javascript:search()"><img src="images/index_top05.gif" alt="搜尋按鈕" height="17"

border="0"></a>


在搜尋結果頁面按回上一頁設定Focus


<body onLoad="setFocus()">




<script LANGUAGE="JavaScript">
function search()
{
document.search_form.p.value = document.search_form.strQuery.value;
  document.search_form.submit();
}
function setFocus()
{
   if(document.search_form.strQuery.value != "請輸入關鍵字")
 document.search_form.strQuery.focus();
}
</script>

=======================
完畢。