开发者

How can I make the cursor stay hidden below an absolute div in IE?

开发者 https://www.devze.com 2023-04-05 14:24 出处:网络
Check out this page in IE 8. Focus on the input box. The blinking cursor appears on top of the blue开发者_JS百科 div. In Chrome and Firefox this does not happen.

Check out this page in IE 8.

Focus on the input box. The blinking cursor appears on top of the blue开发者_JS百科 div. In Chrome and Firefox this does not happen.

Is this a browser bug? Is there a workaround?


That's indeed a problem with IE.

Maybe you can try to use a span element or something as an input field. Then, you can set an event handler to listen to a key pressed.

For example, the following JavaScript snippet allows to insert a character into the innerHTML of an element:

function addChar(element, event) {
    if (!event) event = window.event;
    element.innerHTML += String.fromCharCode(event.keyCode);
}

...and the HTML snippet:

<span onkeypress="addChar(this, event);"></span>

Note that you still need a workaround to prevent the browser to navigate to the previously visited webpage when pressing BACKSPACE.

That can be done with event.preventDefault() for example. Or you can use

<body onkeydown="if(event.keyCode==8||event.keyCode==13)return false;">

or something.

On http://www.mcemperor.nl/test/hidecaret/, you can see an example.

0

精彩评论

暂无评论...
验证码 换一张
取 消