admin管理员组文章数量:1305831
I have <div>Some text</div>
, and i want to make it unclickable (i want elements that under that div to be selected instead this div), unselectable (so user couldn't select text inside this div), but visible... is it possible for IE6 + IE7 + IE8 + IE9?
Update
I just want to render some text on top of picture, but i want picture to be the only one who can catch mouse events.. so i want text to be rendered, but not involved in mouse events at all..
I have <div>Some text</div>
, and i want to make it unclickable (i want elements that under that div to be selected instead this div), unselectable (so user couldn't select text inside this div), but visible... is it possible for IE6 + IE7 + IE8 + IE9?
Update
I just want to render some text on top of picture, but i want picture to be the only one who can catch mouse events.. so i want text to be rendered, but not involved in mouse events at all..
Share Improve this question edited Apr 3, 2011 at 19:29 obenjiro asked Apr 3, 2011 at 19:23 obenjiroobenjiro 3,7607 gold badges49 silver badges83 bronze badges 7- You want to prevent users from copying your content? Nope. – user142019 Commented Apr 3, 2011 at 19:26
- @Ai Is that DIV absolutely positioned? – Šime Vidas Commented Apr 3, 2011 at 19:27
- Not sreal, i just want to render some text on top of picture, but want picture to be the only one who can catch mouse events.. so i want text to be rendered, but not involved in mouse events.. – obenjiro Commented Apr 3, 2011 at 19:28
- @sime-vidas well.. yes.. – obenjiro Commented Apr 3, 2011 at 19:53
- If you have the text as a child of the image div, absolutely positioned over the top, then the events will propagate up to the image div if you do not catch them. The text selection can be blocked via CSS. – Orbling Commented Apr 3, 2011 at 21:26
6 Answers
Reset to default 3 +50You can disable your text by setting the unselectable attribute <p unselectable="on">
and setting the CSS property -moz-user-select: none;
Assuming your text is inside a <p>
you can trigger a click to the image when p is clicked on.
$("p").click(function() {
$(this).parent().find('img').trigger('click')
});
$('img').click(function() {
alert('image clicked');
})
Check working example at http://jsfiddle/pavgY/1/
Try overlaying the image and text with another div (named capturebox
in my example) and capture mouse events on that.
In order for capturebox
to really capture events in IE, it must have a background color set. To make it transparent, I give it an opacity of 0:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3/1999/xhtml">
<head>
<script>
function captureclick(event) {
alert('capurebox');
}
</script>
<style>
.imgbox {
position: absolute;
top: 0px;
left: 0px;
}
.imgbox img {
width: 200px;
height: 200px;
}
.imgbox p {
cursor: default;
position: absolute;
top: 50px;
left: 50px;
}
.capturebox {
filter: alpha(opacity=0);
background-color: white;
height: 200px;
width: 200px;
position: absolute;
left: 0px;
right: 0px;
}
</style>
</head>
<body>
<div class="imgbox">
<img src="yourimage.jpg"/>
<p>Some text</p>
<div class="capturebox" onclick="captureclick(event)"></div>
</div>
</body>
</html>
Here's a working example (at least in Chrome and IE6, can't speak for IE7-9) using Raphael to render the text on top, and a little jQuery to route events appropriately.
(Gotta love marsupials!)
I was surprised to find that the click event pass-through worked in VML in IE6! Also, the VML is not selectable by default, which in this case is nice.
The starting markup is just <img alt="the text you want to show" />
, so it's a pure JS enhancement.
This is basically the SVG-based equivalent of the canvas-based solution proposed by @Eldar.
var element = document.getElementById('content');
element.onselectstart = function () { return false; } // ie
element.onmousedown = function () { return false; } // mozilla
Try this
Could you just place a clear image on top?
You can use canvas to put text ontop of image. Sure HTML5 is not working for IE6 but you can use http://code.google./p/explorercanvas/ googles library to emulate it there.
本文标签: javascriptHTMLIE6IE7IE8IE9unclickable div elementStack Overflow
版权声明:本文标题:javascript - HTML + IE6 + IE7 + IE8 + IE9, unclickable div element - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741809189a2398691.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论