2009年6月26日 星期五

javascript一行檢測瀏覽器

B=(function x(){})[-5]=='x'?'FF3':(function x(){})[-6]=='x'?'FF2':/a/[-1]=='a'?'FF':'\v'=='v'?'IE':/a/.__proto__=='//'?'Saf':/s/.test(/a/.toString)?'Chr':/^function \(/.test([].sort)?'Op':'Unknown'

參考網址
http://jsgears.com/thread-168-1-1.html
http://ajaxian.com/archives/ievv

zeroclipboard複數指定方法--改變大小

原先的reposition函式會提醒你
// reposition our floating div, optionally to new container
// warning: container CANNOT change size, only position
他只會移動位置並不會改變大小
當要指定的元素大小不一時,就有點麻煩了

回頭看在glue()裡創建新的DIV遮罩時會設定下列參數
style.position = 'absolute';
style.left = '' + box.left + 'px';
style.top = '' + box.top + 'px';
style.width = '' + box.width + 'px';
style.height = '' + box.height + 'px';
style.zIndex = zIndex;
而reposition()只有重新定義其中left及top的位置參數
所以可以在reposition()中加入設定width及height這兩行程式碼
但這兩行只是設定style的顯示
最重要的是這一行
this.div.innerHTML = this.getHTML( box.width, box.height );
它是將在getHTML()中寫好導入flash的html丟入div中,使它成為一個flash元件
重新呼叫此函式才能變更flash的大小

將上列三行加入reposition即可
不過在IE及FireFox上都運行無誤,在Chrome,Safari上則會卡卡的,Chrome有時會完全卡住
其他的瀏覽器我就沒去試了,這也是他為什麼不讓我們改變大小的原因吧

2009年6月25日 星期四

zeroclipboard複數指定方法

在firefox中預設是將剪貼簿關掉的,不像IE可以自由取用
在網路中翻了又翻找到了zeroclipboard!!
zeroclipboard解決了跨瀏覽器使用clipboard的問題
http://code.google.com/p/zeroclipboard/
之前也有使用flash的方法
http://www.jeffothy.com/weblog/clipboard-copy/
但到了flash10就無法使用
http://bshadow.pixnet.net/blog/post/23246050


下面原始碼出處http://bowser.macminicolo.net/~jhuckaby/zeroclipboard/multiple.html

<\html>
<\head>
<\title>Zero Clipboard Multiple Test<\/title>

<\style type="text/css">
body { font-family:arial,sans-serif; font-size:9pt; }

div.multiple {
float: left;
background-color: white;
width:200px; height:200px;
border:1px solid #ccc;
margin:5px;
cursor: pointer;
font-size: 14pt;
}

div.multiple.hover {
background-color: #ddd;
}
<\/style>

<\script type="text/javascript" src="./flash/jquery.js"><\/script>
<\script type="text/javascript" src="./flash/ZeroClipboard.js"><\/script>

<\script language="JavaScript">
var clip = null;

function init() {
ZeroClipboard.setMoviePath( './flash/ZeroClipboard.swf' );
// setup single ZeroClipboard object for all our elements
clip = new ZeroClipboard.Client();
clip.setHandCursor( true );

// assign a common mouseover function for all elements using jQuery
//將html 中宣告的div元素以class為單位丟入jQuery中
$('div.multiple').mouseover( function() {
// set the clip text to our innerHTML
clip.setText( this.innerHTML );

// reposition the movie over our element
// or create it if this is the first time
//這裡指的div是javascript產生的div元素,也就是附屬在clip底下的div,並非上一段所提到html的div,當程式呼叫到clip.glue()時js會產生一個div罩住你所指定的元素,所以這一段是在說如果先前已有產生div那麼便將他重新定位至現在指定的元素(this),否則就創造一個新的div遮罩
if (clip.div) {
clip.receiveEvent('mouseout', null);
clip.reposition(this);
}
else clip.glue(this);

// gotta force these events due to the Flash movie
// moving all around. This insures the CSS effects
// are properly updated.
clip.receiveEvent('mouseover', null);
} );

// add an event handler which fires after text is copied to the clipboard
// and change the color of the underlying DOM element
clip.addEventListener('complete', function(client, text) {
var div = client.domElement;
div.style.backgroundColor = '#bff';
} );
}
<\/script>


<\/head>

<\body onLoad="init()">
<\h1>Zero Clipboard Multiple Test<\/h1>

<\div class="multiple">Hello there<\/div>
<\div class="multiple">These are all equally sized DOM elements.<\/div>
<\div class="multiple">Click on any of them to copy their text to the clipboard.<\/div>
<\div class="multiple">This is all done with a single ZeroClipboard object.<\/div>

<\div class="multiple">The only catch is, all the elements must be the same size.<\/div>
<\div class="multiple">Bye bye!<\/div>
<\div style="clear:both;"><\/div>

<\br/><\br/>
You can paste text here if you want, to make sure it worked:<\br/>
<\textarea id="testarea" cols=50 rows=10><\br/>
<\input type=button value="Clear Test Area" onClick="document.getElementById('testarea').value = '';"/>

<\/body>

<\/html>


當初就是兩個div搞混了 所以改用td時就會有問題(做了兩個div遮罩出來)

by the way
IE只需要一行
window.clipboardData.setData("Text",A.innerText);

2009年6月22日 星期一

[PHP]mysql_real_escape_string

get_magic_quotes_gpc();
GPC--get,post,cookie
如果伺服器替參數值都加上//回傳true

$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

用stripslashes()刪除slash
//----------------------------------------------------------------------
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
如果輸入值含用',"等使之跳脫以免影嚮sql query 或造成漏洞

[PHP]避免重新載入或上下一頁的重覆輸入

表單用POST丟給自己來做就好了@@
< method="post" action="self.php">

------------------------------------------


<\html\>
<\body\>
<\form method="POST" action="xxxx.php"\>
<\input type="hidden" name="check" value="true"\>
<\input type="submit"\>
<\/form\>
<\/body\>
<\/html\>

太長太複雜的話用require的好了

2009年6月19日 星期五

開通!!

開通了 不知道好不好玩!?


不能使用style標籤....= =
也沒有script標籤 囧

2009年6月18日 星期四

發佈排程

哇咧....原來可以排時間才公佈文章
那我剛才第一篇打的「開通!」不就是不是第一篇了....囧

javascript來亂

function confirmit(no,table,ymd,thisname){
var text = './etrc_ag_calendar_insert.php?method=confirm&no='+no+'&ymd='+ymd+'&table='+table;
var time_s = getNextElement(thisname);
var time_e = getNextElement(time_s);
var depart = getNextElement(time_e);
var memo = getNextElement(depart);
var temp = '&time_s='+time_s.value+'&time_e='+time_e.value+'&depart='+depart.value+'&memo='+memo.value.replace("&","\&");//避免被當成下一個元素

var query = text + temp;
// document.write(query);
location.href=query;