Make images not selectable - html

I am making a website in dreamweaver CS5. I exported the images from photoshop an inserted them into a table. When I view the site all the images are selectable(you are able to drag them to your desktop). How do I change this??? I want to do it with an onclick method in addition how would I achieve this?
<td><img src="images/people_03.png" name="one" width="1000" height="156" id="one" ONCLICK="closeimages();"/></td>

I stumbled upon this question while struggling with the same problem but the accepted answer was not a possible solution for me.
I used the info found here , in particular adding the following styles to my body, inside the css (this worked for me in Firefox, Chrome and Opera, I cannot test for IE)
-moz-user-select: none;
-webkit-user-select: none;
user-select: none;
The unselectable html tag seems also helpful, but it's apparently supported only by IE and Opera:
<img src="1.jpg" unselectable="on">
as well as the javascript solution, that is said to work on IE and webkit browsers:
<script>
window.onload = function() {
document.body.onselectstart = function() {
return false;
}
}
</script>
Note. As Albert Renshaw pointed in the comment this method no longer works in Chrome > 50.

I would use pointer-events: none; in my CSS
img {
pointer-events: none;
}

Reliable Pure CSS Solution
Applying the following 2 CSS properties to your <img> element(s) will achieve exactly what you described:
pointer-events: none;
user-select: none;
This works reliably across all modern browsers.
Example: (Try to select and drag the image with your cursor! :D)
img {
pointer-events: none;
user-select: none;
}
<img src="https://source.unsplash.com/random/200x200" alt="sample image" />
The only downside is that pointer-events: none causes your :hover, :active and other pointer-related CSS pseudo-classes to stop working.
In order to solve this, you should use a <div> or something as a wrapper for your <img> and then apply your :hover, :active pseudo-classes on that wrapper as opposed the <img> itself.
Example:
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
/* Don't mind the code above... */
.image-wrapper {
transition: ease .5s;
}
.image-wrapper:hover {
transform: scale(1.3)
}
.image {
pointer-events: none;
user-select: none;
}
<div class="image-wrapper">
<img class="image" src="https://source.unsplash.com/random/200x200" alt="sample image" />
</div>
If you also don't want to or can't change your HTML markup, then you're gonna have to resort to some JavaScript:
imgElement.addEventListener('selectstart', () => false);

Easiest way I think would be to make the images as css background images to each cell

Related

HTML <details> tag does not work in IE/Edge

I am trying to add additional toggleable section that user can show and hide.
My requirements:
supported on major browsers (Opera, Chrome, Edge, IE11, Firefox, Safari on Mac)
no javascript
And was thinking of using the <details> tag, however the code
<details>
<summary>Toggle</summary>
<p>Hideable</p>
</details>
does not work on the Edge / IE browsers.
Can I anyhow "make" it work, or is there anything else I can use for that task? Hacks are OK, as long as no javascript is present.
You can add a polyfill once on a page to make all the <details/>s on the page work:
<!-- Inside the body -->
<script src="//cdn.jsdelivr.net/npm/details-polyfill#1/index.min.js" async></script>
I know this is a JS solution but it doesn't require writing any JS for each individual <details/>. It can be used with a text written in a WYSIWYG editor.
This would be the suggested :checked method utilizing a hidden checkbox:
.toggler {
display: none;
}
.toggler+.toggler-content {
max-height: 0;
opacity: 0;
overflow: hidden;
transition: all .4s ease-in-out;
}
.toggler:checked+.toggler-content {
max-height: 1000px;
opacity: 1;
}
<div>
<label for="toggler-id-1">Toggle</label>
<input type="checkbox" id="toggler-id-1" class="toggler" />
<div class="toggler-content">Hideable</div>
</div>
I would still prefer going with #Finesse's solution because it allows you to use the semantically correct HTML element for the purpose.
Copy the below script and put it in a js file and then import it or write it directly in tags. This worked for me.
!function(e,t){"function"==typeof define&&define.amd?define(t):"object"==typeof exports?module.exports=t():t()}(0,function(){var o="details",i="summary";(function(){var e=document.createElement(o);if(!("open"in e))return!1;e.innerHTML="<"+i+">a</"+i+">b",document.body.appendChild(e);var t=e.offsetHeight;e.open=!0;var n=t!=e.offsetHeight;return document.body.removeChild(e),n})()||(document.documentElement.className+=" no-details",window.addEventListener("click",function(e){if("summary"===e.target.nodeName.toLowerCase()){var t=e.target.parentNode;if(!t)return;t.getAttribute("open")?(t.open=!1,t.removeAttribute("open")):(t.open=!0,t.setAttribute("open","open"))}}),function(e,t){if(document.getElementById(e))return;var n=document.createElement("style");n.id=e,n.innerHTML=t,document.getElementsByTagName("head")[0].appendChild(n)}("details-polyfill-style","html.no-details "+o+":not([open]) > :not("+i+") { display: none; }\nhtml.no-details "+o+" > "+i+':before { content: "▶"; display: inline-block; font-size: .8em; width: 1.5em; }\nhtml.no-details '+o+"[open] > "+i+':before { content: "▼"; }'))});
If you don't want that arrows then just remove this part from end
+o+" > "+i+':before { content: "▶"; display: inline-block; font-size: .8em; width: 1.5em; }\nhtml.no-details '+o+"[open] > "+i+':before { content: "▼"; }'

Remove blue frame from image with link [duplicate]

I am making a custom Application in Android. I am displaying a html page with an img tag inside a div.
<div class="press">
<img src="but.png" width="150" height="62" border="0"/>
</div>
In the javascript I am writing:
$(".press").bind("click",function()
{
//display something
});
When I click on the image, the click is working but the image is surrounded with a blue overlay.
Image 1
Image 2 when image clicked
I dont understand how to remove it. I have tried many ways but none of the answers work. Please help. Thanks
You can prevent selection on your page through css. You can change the * selector to the element selector you want to prevent from selection.
/*IE9*/
*::selection
{
background-color:transparent;
}
*::-moz-selection
{
background-color:transparent;
}
*
{
-webkit-user-select: none;
-moz-user-select: -moz-none;
/*IE10*/
-ms-user-select: none;
user-select: none;
/*You just need this if you are only concerned with android and not desktop browsers.*/
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}
input[type="text"], textarea, [contenteditable]
{
-webkit-user-select: text;
-moz-user-select: text;
-ms-user-select: text;
user-select: text;
}
Try this:
CSS
.press, img, .press:focus, img:focus{
outline: 0 !important;
border:0 none !important;
}
You could use CSS:
** HTML **
<button class="press">
<img src="but.png" width="150" height="62" border="0"/>
</button>
** CSS **
.press{
outline-width: 0;
}
.press:focus{
outline: none;
}
Answer take from here: How to remove the border highlight on an input text element
It may be the background color or the border color on the div that includes the button. Else
use a code like following to remove the css after click completely
$("#myButton").click(function(){
$("#displayPanel div").removeClass('someClass');
});

How do I remove the zoom icon that appears when hovering over image?

I'm working on a site that uses this bootstrap theme. When the mouse hovers over any image a zoom icon appears - how do I remove it?
I have tried removing class="zoomIcon" and looked on this site as well as searching on Google.
HTML:
<div class="product-main-image-container">
<img src="../../images/products/prod1.png" alt="" class="product-loader" style="display: none;">
<span class="thumbnail product-main-image" style="position: relative; overflow: hidden;">
<img src="../../images/products/prod1.png" alt="">
<img src="../../images/products/prod1.png" class="zoomImg"
style="position: absolute; top: -0.0456852791878173px; left: -1.23350253807107px; opacity: 0; width: 400px; height: 400px; border: none; max-width: none; max-height: none;">
</span>
</div>
You can add this to your CSS:
<style>
img:hover {
cursor: default;
}
</style>
I hope this helped you!
You can override this cursor behavior by either modifying the CSS that is making it happen (it looks like a CSS file called style.css) or by writing your own rule to make it stop.
The rule is on .product-main-image in line 432 of the style.css file, and to overwrite it, you would need a rule like this:
.product-main-image{cursor:default;} or any other cursor style you wish
class product-main-image has the zoom icon:
.product-main-image{
cursor: zoom-in; cursor: -webkit-zoom-in; cursor: -moz-zoom-in
}
http://screencast.com/t/NcdCxnrrW4
Just remove this class from the span or change the cursor on this class to something else http://www.w3schools.com/cssref/pr_class_cursor.asp
This is not from a class.
img:hover{
cursor:pointer;
}
Source : https://developer.mozilla.org/en-US/docs/Web/CSS/cursor1
Unrelated : You shouldn't leave the 'alt' tags empty, they are important to accessibility and SEO.
You can use the CSS cursor property.
Then you can just assign it to default on hover
img:hover {
cursor: default;
}

How to remove selection on images

I want to remove the selection-highlight on all images on my page.
I found some useful additions like :
CSS
img {
-webkit-user-select:none;
-khtml-user-select:none;
-moz-user-select:none;
-o-user-select:none;
user-select:none;
pointer-events:none
}
But when I press down my mouse button and select multiple things or press Ctrl+A for "select all" my images get highlighted with a blue shade.
I tried to change it via :
CSS
img::selection {background:transparent;color:inherit;}
img::-moz-selection {background:transparent;color:inherit;}
But that don't have any effect.
Does someone have a useful solution or is there none yet ?
P.S. : I don't care about selecting my images - I just want to get rid of that blue shape.
Here goes a wacky solution I came up with...
1) After some testing I found that this only occurs on mozilla. Other browsers don't show the blue selection on images when the code
img::selection {
background: transparent;
}
is set.
2) Even mozilla - only has a problem with image elements. But other elements with a background-image obey the ::selection rule.
So technically we could work around this assuming we add an empty span in our markup after each img element which we set to display:none;
Then we can add some CSS which will only run in firefox which sets the images to display:none and places a background-image on the adjacent span.
Like this:
FIDDLE
**
img::selection {
background: transparent;
}
img + span {
display: none;
}
#-moz-document url-prefix() {
img {
display: none;
}
img + span {
background: url(http://placehold.it/200x200) no-repeat;
width: 200px;
height: 200px;
display: block;
}
}
<div>Hello there </div>
<img src="http://placehold.it/200x200" /><span></span>
<div>Hello there </div>
1: http://jsfiddle.net/GMuzV/30/
This disabled highlighting on a DOM element:
function disableSelection(target){
if (typeof target.onselectstart!="undefined") // if IE
target.onselectstart=function(){return false}
else if (typeof target.style.MozUserSelect!="undefined") // if Firefox
target.style.MozUserSelect="none";
else // others
target.onmousedown=function(){return false;}
target.style.cursor = "default";
}
Use it like this:
disableSelection(document.getElementById("my_image"));

Phone Gap: Disable text selection in a webview

I am working on a Phone Gap Project.I am using HTML,JAVA SCRIPT and CSS.
I have implemented onclick ,mapping and ahref functionality in my project.While using this functionality either for onclick or mapping or ahref --while selecting the image or text it gets highlighted.
I don't want it get highlighted.I tried implementing this following code
noSelect
{
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-o-user-select: none;
user-select: none;
}
But,this code made no difference in the SELECTING VIEW.
So,please suggest me a way to handle this and solve my problem.
EDIT:
This is how i have used it in mapping and image but it isn't working.
mapping
<div id="main" class="main" ><img src="img/abc.png" alt="abc" usemap="#abc" class="noSelectInputBox:focus"/></div>
image source
document.getElementById("detail").innerHTML = '<img src="img/image1.png" onclick="detail()" class="noSelectInputBox:focus"/> '
try adding the following css to yours:
noSelectInputBox:focus
{
-webkit-tap-highlight-color:rgba(0,0,0,0);
outline:none;
-webkit-focus-ring-color:rgba(0 0 0 0);
}
Hope that helps.
Writing the following code in your css file. While using this we can disable highlighting the contents on touch.
*{
/* Prevent any object from being highlighted upon touch event*/
-webkit-tap-highlight-color: rgba(0,0,0,0);
}