2012年11月27日 星期二

判斷瀏覽器的不同加載不同css

<link href="index2/style2.css" rel="stylesheet" type="text/css" />
 <!--[if IE 6]><link href="index2/ie6.css" rel="stylesheet" type="text/css" /><![endif]-->
 <!--[if gte IE 7]><link href="index2/ie7.css" rel="stylesheet" type="text/css" /><![endif]-->
<link href="#" id="notIEcssId" rel="stylesheet" type="text/css"/>

<script type="text/javascipt" >

$(document).ready(function(){
         
 if( ! $.browser.msie) { 
        $("#notIEcssId").attr("href","notIEcss.css");
    });

</script>


jquery中利用navigator.userAgent.indexOf来判断浏览器类型,并进行了一下处理,如果不想使用jquery,稍为修改下代码就可以为自己所用

jquery判断浏览器的源码(jquery1.31为例)

Js代码:
  1. var userAgent = navigator.userAgent.toLowerCase();   
  2.   
  3. // Figure out what browser is being used   
  4. jQuery.browser = {   
  5.     version: (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [0,'0'])[1],   
  6.     safari: /webkit/.test( userAgent ),   
  7.     opera: /opera/.test( userAgent ),   
  8.     msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),   
  9.     mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )   
  10. };  

 

version---浏览器版本

msie----ie浏览器(Microsoft Internet Explorer)

mozilla-火狐浏览器

opera--opera浏览器

2012年10月17日 星期三

detect iframe change from form submit target

<script language="JavaScript">
$(function(){
var f = $('#hidden_frame')[0];
f.attachEvent ? f.attachEvent('onload', onFrameLoad) :
f.addEventListener('load', onFrameLoad, false);

function onFrameLoad() {
$("#hidden_frame").css("height",500);
$("#mainform").hide();
};
});
</script>

iframe 調整高度

資料來源 :http://wadevelop.blogspot.tw/2009/03/iframe-auto-heightiframe.html

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js"></script>
<script type="text/javascript">
  $(document).ready(function(){
    iframe_auto_height(); //當文件ready時才能正確取得iframe內容的高度
  });
  //iframe auto height主程式
  function iframe_auto_height(){
    if(!this.in_site()) return;
    var iframe;
    $(parent.document).find("iframe").map(function(){ //找到自己的iframe
      if($(this).contents().get(0).location == window.location) iframe = this;
    });
    if(!iframe) return;//no parent
    var content_height = $("body").height()+50;
    content_height = content_height < 300 ? 300 : content_height; //設定最小高度
    content_height = typeof content_height == 'number' ? content_height+"px" : content_height;
    iframe.style.height = content_height;
  }
  //判斷是否在網頁的iframe之中
  function in_site(){
    if(parent != window && this.is_crosssite() == false) return(true);
    return(false);
  }
  //判斷是否跨站(可能是別人嵌入了你的網頁)
  function is_crosssite() {
    try {
      parent.location.host;
      return(false);
    }
    catch(e) {
      return(true);
    }
  }
</script>

2012年10月14日 星期日

Rewrite rule

RewriteCond %{HTTP_HOST} !^www.web.com [NC] #請求的主機中URL不是www.web.com ,[NC]的意思是忽略大小寫

RewriteCond %{HTTP_HOST} !^$ #求的主機中URL不為空

RewriteRule ^/(.*) http://www.web.com/ [L]
#含義是如果Client請求的主機中的URL符合上述條件,則直接進行跳轉到http://www.web.com/,[L]意味著立即停止重寫操作,並不再應用其他重寫規則。這裡的.*是指匹配所有URL中不包含換行字符,()括號的功能是把所​​有的字符做一個標記,以便於後面的應用.就是引用前面裡的(.*)字符。

1) R[=code](force redirect) 強制外部重定向[r=301]
2) F(force URL to be forbidden)禁用URL,返回403HTTP狀態碼。
3) G(force URL to be gone) 強制URL為GONE,返回410HTTP狀態碼。
4) P(force proxy) 強制使用代理轉發。
5) L(last rule) 表明當前規則是最後一條規則,停止分析以後規則的重寫。
6) N(next round) 重新從第一條規則開始運行重寫過程。
7) C(chained with next rule) 與下一條規則關聯
8) T=MIME-type(force MIME type) 強制MIME類型
9) NS (used only if no internal sub-request) 只用於不是內部子請求
10) NC(no case) 不區分大小寫
11) QSA(query string append) 追加請求字符串
12) NE(no URI escaping of output) 不在輸出轉義特殊字符
例如:RewriteRule /foo/(.*) /bar?arg=P1\%3d$1 [R,NE] 將能正確的將/foo/zoo轉換成/bar?arg=P1=zoo
13) PT(pass through to next handler) 傳遞給下一個處理
例如:
RewriteRule ^/abc(.*) /def$1 [PT] # 將會交給/def規則處理
Alias​​ /def /ghi
14) S=num(skip next rule(s)) 跳過​​num條規則
15) E=VAR:VAL(set environment variable) 設置環境變量

. 換行符以外的所有字符
\w匹配字母或數字或下劃線或漢字
\s匹配任意的空白符
\d匹配數字
\b匹配單詞的開始或結束
^匹配字符串的開始
$匹配字符串的結束
*重複零次或更多次
*重複零次或更多次
+重複一次或更多次
?重複零次或一次
{n}重複n次
{n,}重複n次或更多次
{n,m}重複n到m次
應用替換時,前面第一個()中匹配的內容後面就用$1引用,第二個()中匹配的就用$2應用……
推荐一個實用的正則在線測試網站http://www.regextester.com/
我們來分析一下discuz7.0 搜索引擎優化htaccess 裡面的重寫。
RewriteRule ^forum-([0-9]+)-([0-9]+)\.html$ forumdisplay.php?fid=$1&page=$2
首先加入用戶通過nbphp.com/forum-2-3.html 訪問discuz論壇,那麼先通過.htaccess過濾,看看是否需要.htaccess引導一下用戶,如果滿足列出的一系列RewriteCond的條件那麼就進行重寫,discuz的沒有列出RewriteCond 所以應該全部都進行重寫。所以開始進行轉寫,forum-2-3.html 這個正好符合列出的^forum-([0-9]+)-([0-9]+)\.html$ 正則表達式。並且$1 為2 ,$2為3 ,所以代入後面,即forumdisplay.php?fid=2&page=3 加上前面的RewriteBase 指定的文件目錄,那麼就帶他到製定目錄的forumdisplay.php?fid=2&page=3 。

2012年7月31日 星期二

Ubuntu LAMP

關閉 Apache2 服務或重新啟動:

sudo service apache2 restart  # 參數可以是 restart 或 start 等
sudo nano /etc/apache2/apache2.conf
mysqladmin -uroot -p flush-logs  
mysqldump dbname -uroot -p --opt > phpbb2_20020601.sql

#su  切換至root權限,但並不載入相關設定值;
#su -  切換至root權限,並且載入相關設定值;
#sudo 切換至暫時性root權限

把指令執行結果寫入檔案內【> 重新寫入、 >> 最尾寫入】
echo "" > error.log  

2012年5月28日 星期一

Youtube相關

YouTube 預設顯示字幕 

只需將 &cc_load_policy=1 加入到影片的內嵌程式碼即可。

ref:http://support.google.com/youtube/bin/answer.py?hl=zh-Hant&answer=140174


-------------------------
幫Youtube影片加上字幕

2012年5月27日 星期日

PHP 補救ini沒有的一些設定

ini_set('display_errors', 1); 
ini_set('log_errors', 1); 

error_reporting(E_ALL);

-----------------------------
extract(array,extract_rules,prefix)
EXTR_OVERWRITE - 默認。如果有衝突,則覆蓋已有的變量。
  • EXTR_SKIP - 如果有衝突,不覆蓋已有的變量。
  • EXTR_PREFIX_SAME - 如果有衝突,在變量名前加上前綴prefix。自PHP 4.0.5 起,這也包括了對數字索引的處理。
  • EXTR_PREFIX_ALL - 給所有變量名加上前綴prefix(第三個參數)。
  • EXTR_PREFIX_INVALID - 僅在非法或數字變量名前加上前綴prefix。本標記是 PHP 4.0.5 新加的。
  • EXTR_IF_EXISTS - 僅在當前符號表中已有同名變量時,覆蓋它們的值。其它的都不處理。可以用在已經定義了一組合法的變量,然後要從一個數組例如$_REQUEST 中提取值覆蓋這些變量的場合。本標記是 PHP 4.2.0 新加的。
  • EXTR_PREFIX_IF_EXISTS - 僅在當前符號表中已有同名變量時,建立附加了前綴的變量名,其它的都不處理。本標記是 PHP 4.2.0 新加的。
  • EXTR_REFS - 將變量作為引用提取。這有力地表明了導入的變量仍然引用了var_array 參數的值。可以單獨使用這個標誌或者在extract_type 中用OR 與其它任何標誌結合使用。本標記是 PHP 4.3.0 新加的。

parse_str(string,array) 函數把查詢字符串解析到變量中。

2012年5月21日 星期一

wFORMS的自訂檢查

<script type="text/javascript">

wFORMS.functionName_formValidation = "doPostBack";
function doPostBack(e)
{
if(!e) e = window.event;
if(wFORMS.behaviors['validation'].run(e))
{
///自己寫的檢查碼
errMsg='請設定人數限制值';
errField = document.getElementById('Men_closed');

if(errMsg !='')
{
alert(errMsg);
wFORMS.behaviors['validation'].showError(errField, errMsg);
// we need to prevent the submission:
return wFORMS.helpers.preventEvent(e);

}

return true;
}
}

</script>

Jquery 使用小技巧

radio value:
$('input[name=XXname]:radio').click()
$(this).val();

變更狀態
$('input[name=XXname][value="1"]').attr('disabled',true); //不能選
$('input[name=XXname][value="0"]').attr('checked',true); //選取

checkbox
$('input[name=XXname]:checked').val();



$("input[type='radio'][name='radio']:checked").length == 0  沒有任何單選框被選中

$('input[type="radio"][name="radio"]:checked').val(); // radio被選中項的值

$("input[type='radio'][name='radio'][value='2']").attr("checked", "checked");// 設置value = 2的一項為選中

$("input[type='radio'][name='radio']").get(1).checked = true; // 設置index = 1,即第二項為當前選中

$("input[type='radio'][name='radio']").eq(1).attr(disabled,true);

[selector].after(content):
[content].insertAfter(selector):
把p加在div之前:
[selector].before(content):
[content].insertBefore(selector);


==========================================================
在div中加入p
$('#div1').append('<p>')
把p加入到div中
$('<p/>').appendTo($('#div1'))

======================================================
show 出 json 內容

<script type="text/javascript" charset="utf-8">
$('input').click(function(){
$.ajax({
url:'http://xxx.xxx.xx/get_json.php',
//url:'get_json.php',
dataType:'json',
success:function(data){
$('#show').append(parse_json_Obj(data,0));
}
});
});
var string ='';
function parse_json_Obj(obj,index){
$.each(obj,function(i,v){
if(typeof v =='object'){
string = string+"<div style='padding-left:"+20*index+"px'>"+ v +":</div>"
parse_json_Obj(v,index+1);
}else{
string = string+"<div style='padding-left:"+20*index+"px'>"+n+"</div>"
}
});
return string;
}
</script>

2012年4月13日 星期五

IE FE CHROME問題解決方案

1.IE 在設定table width=100% 時,會忽略上一層的div 的 padding 值,只要在上一層 style中加入 zoom:1 就可以使IE恢復標準顯示!!

2.FF 會有 margin-top 失效的問題,解決方式有二
   A:在上層加入overflow:hidden
   B:在子元素加入position:absolute

2012年4月7日 星期六

用 jquery 直接顯示source code

plugin JQUERY

$(function() { 	$('.demo').each(function() { 		var source = $('.demo_source', this);  		source.hide().find('code').text($.trim($('.demo_frame', this).html())); 		$('.view_source', this).click(function() { 			source.toggle(); 			return false; 		}); 	}); });

參考範例
<h2>Examp</h2>
<div class="demo">
<p><a href="#" class="view_source">View Source</a></p>
<pre class="demo_source">
  <code></code>
</pre>

<div class="demo_frame">
  <script type="text/javascript">
    $(function() {
        UrCode....        });
    });
  </script>

  <input type="file" name="file" id="file1"/>
</div>
</div>

參考網址
http://lagoscript.org/jquery/upload/demo?locale=en

2012年3月4日 星期日

PHP 文字轉碼UNICODE


// 使用 iconv

$unicode_html = '&#' .base_convert(bin2hex(iconv('UTF-8', 'UCS-4', $str)), 16, 10)';'; 



// 使用 mb_convert_encoding

$unicode_html = '&#' .base_convert(bin2hex(mb_convert_encoding($str, 'ucs-4', 'utf-8')), 16, 10)';';




//回轉
$str = mb_convert_encoding($unicode_html, 'UTF-8', 'HTML-ENTITIES');