HOBALL 筆記簿

July 22, 2009

Javascript fix for the failure of IE to pass HTTP_REFERER in setting new URL on location.href

Filed under: Javascript — Tags: , , , , — hoball @ 12:49 pm

Setting a new URL using location.href will change the HTTP_REFERER on Firefox/Opera/Safari, but NOT on IE

Here is the hack to fix this (quoted from here):

/* location.href FIX for MSIE */
//http://blogs.msdn.com/ie/archive/2008/10/30/hot-off-the-press-codefocus-on-ie8.aspx#9028128
function setHref(url) {
    var isIE = (navigator.appName.indexOf("Microsoft")!=-1) ? true : false;

    if (!isIE) {
        //Standards based browsers
        parent.location.href = url; // Set target: self. / parent. / top.
    } else {
        var lha = document.getElementById(‘_lha’);
            if(!lha){
                lha = document.createElement(‘a’);
                lha.id = ‘_lha’;
                lha.target = ‘_parent’;  // Set target: for IE
                document.body.appendChild(lha);
            }
            lha.href = url;
            lha.click();
    }
}

October 31, 2008

Javascript innerTEXT innerHTML

Filed under: Javascript — Tags: , , , — hoball @ 2:26 pm

一圖勝萬字解釋

October 21, 2008

代碼小技巧:一鍵註釋

Filed under: Coding/Programming — Tags: , , , — hoball @ 12:55 pm

轉載自 http://www.cnblogs.com/biggates/archive/2008/02/28/1085216.html

書寫(和調試)大段大段的代碼的過程中,經常遇到頻繁的註釋和取消註釋的麻煩吧。今天在Ajaxian上學到一招,可以非常方便地對代碼進行註釋和取消註釋:

foo();
/**//*
bar();
baz.foo = 200;
return{
dolly:clone()
}
//
*/

簡單地說,就是把表示區塊註釋的 /* 和 */  改成  /* 和 //*/ ,代碼的修改量只有一個 // 而已。

之後,只要在 /* 的前面加上或刪除一個 / ,就能切換整塊註釋的狀態了。

foo();
//*
bar();
baz.foo
= 200;
return{
dolly:clone()
}

// */


悟透JavaScript

Filed under: Javascript — Tags: , — hoball @ 12:52 pm

轉載李戰(leadzen)自http://www.cnblogs.com/leadzen/archive/2008/02/25/1073404.html

引子

編程世界裡只存在兩種基本元素,一個是數據,一個是代碼。編程世界就是在數據和代碼千絲萬縷的糾纏中呈現出無限的生機和活力。

數據天生就是文靜的,總想保持自己固有的本色;而代碼卻天生活潑,總想改變這個世界。
(more…)

Blog at WordPress.com.