おま、このJavaScriptの挙動は無いだろ・・・IEちょっと表に出ろ。
アンカーを拾って、クリックを無効にする関数をセットしたかっただけなのに、
var e = document.getElementById('hoge_link');
e.setAttribute('onclick', 'return false;');
何でこれで動かねーんだよ! と小一時間悩んでしまったよ。
setAttributeの動作が他のブラウザと異なるため、new Functionしないとだめみたい。
var e = document.getElementById('hoge_link');
if(navigator.userAgent.toLowerCase().indexOf('msie') != -1) {
//IEではnew Function
e.setAttribute('onclick', new Function("return false;"));
}
else {
e.setAttribute('onclick', 'return false;');
}
if(e.getAttribute('onclick') != undefined) {
//removeAttributeは普通に出来る
e.removeAttribute('onclick');
}
知らなきゃ解決出来ない問題が多過ぎるよね。
最近のツッコミ
参号館
日記(ariyasacca)