偽蝦米的作者寫了一個很棒的網頁程式Hyper Liu,讓沒有裝嘸蝦米、沒有跑偽蝦米、甚至是沒有裝中文的人也能靠著嘸蝦米拆碼打出中文字,真正不用安裝、不用執行任何程式的好東西!以後出國,如果想在機場的電腦打幾個中文字,就可以用 Hyper Liu 來代勞,真是太讚了!

但是呢,實際使用起來,在 IE 裡沒問題,在 Firefox 裡卻出不了字,檢查了一下 Firefox 裡的 JavaScript Console,會看到 “document.selection has no properties” 這個訊息!

查了半天,才發現 Netscape 系列的瀏覽器(如 Firefox) 不支援 document.selection,這可真傷腦筋,怎麼辦才好呢?

這個網頁提供了一些線索,我模仿裡面的做法,發現可以把下面這段 JavaScript 的程式碼

function SendWord(s) {
var r = document.selection.createRange();

r.text = s;
r.select();
}

改成

function SendWord(s) {
var input = document.forms[’luke’].elements[’test1′];

// luke is the name of a form while test1 is the name of a textarea
var pos;

input.focus();
pos = input.value.length;
input.value = input.value.substr(0, pos) + s + input.value.substr(pos);
}

而且,這段新的程式碼在 Firefox 和 IE 下都可以執行!

我已經把這段程式碼回給偽蝦米的作者,就等他改了。

============以下是2006.01.23加進來的============

作者已經正式公開這個程式,並且將 link 改到 http://liu.twbbs.org/hliu/

我重看了上面所提的網頁,再把 SendWord() 修改為如下,

function SendWord(s) {
if(typeof document.selection != ‘undefined’) {
var r = document.selection.createRange();
r.text = s;
r.select();
} else if(typeof txt.selectionStart != ‘undefined’) {
var start = txt.selectionStart, end = txt.selectionEnd;
var pos = start + s.length;

txt.value = txt.value.substr(0, start) + s + txt.value.substr(end);
txt.selectionStart = pos;
txt.selectionEnd = pos;
} else {
txt.value += s;
}
}

arrow
arrow
    全站熱搜

    liuzmd1 發表在 痞客邦 留言(0) 人氣()