Jump to content

dis/enable mouse's select


taith

Recommended Posts

the disable works perfectly... however the reenableing on select tags, doesnt  :-[ any ideas?

function disablemouse(){
var target=document.body;
target.onselectstart=function(){return false}
target.onmousedown=function(){return false}
}

function enablemouse(){
this.onselectstart=function(){return true;}
this.onmousedown=function(){return true;}
}

Link to comment
https://forums.phpfreaks.com/topic/50826-disenable-mouses-select/
Share on other sites

this still doesnt work... its not giving me any errors, so it is "working"... just not as its supposed to... :-(

<s cript>
function disablemouse(){
document.body.onselectstart=function(){return false;}
document.body.onmousedown=function(){return false;}
document.body.style.MozUserSelect="none";
}

function enablemouse(loc){
loc.onselectstart=function(){return true;}
loc.onmousedown=function(){return true;}
return true;
}
window.onload=disablemouse;
</s cript>
<span onmouseover="javascript:enablemouse(this);">i dont work either</span>

don't know if this will work in your circumstances, but try saving the event vectors before you mod them, and then restore the saved vectors.

var saveonselect = document.body.onselectstart;
var saveonmousedown = document.body.onmousedown;

function disablemouse(){
var target=document.body;
target.onselectstart=function(){return false}
target.onmousedown=function(){return false}
}

function enablemouse(){
this.onselectstart = saveonselect;
this.onmousedown = saveonmousedown;
}

YAY! it works! sorta....

now... i'm no js expert... but this only works once... ??? ??? ???

 

<s cript>
var saveonselect = document.body.onselectstart;
var saveonmousedown = document.body.onmousedown;

function disablemouse(){
var target=document.body;
target.onselectstart=function(){return false}
target.onmousedown=function(){return false}
}

function enablemouse(){
this.onselectstart = saveonselect;
this.onmousedown = saveonmousedown;
}
window.onload=disablemouse;
</s cript>

<span onmouseover="javascript:enablemouse();" onmouseout="javascript:disablemouse();">text</span>
test

 

i mouseover the span, it allows me to highlight, mouseout, i cant highlight, i mouseover, i still cant highlight... ???

scratch that... still doesnt work... doesnt enable anything ever...

 

<sc ript>
var saveonselect=document.body.onselectstart;
var saveonmousedown=document.body.onmousedown;

function disablemouse(){
document.body.onselectstart=function(){return false;}
document.body.onmousedown=function(){return false;}
}

function enablemouse(){
document.body.onselectstart=saveonselect;
document.body.onmousedown=saveonmousedown;
}
</sc ript>
<body onload="javascript:disablemouse();">
<span onfocus="javascript:enablemouse();" onmouseout="javascript:disablemouse();">text</span>test

try changing the order of the 2 statements:

function enablemouse(){
document.body.onselectstart=saveonselect;
document.body.onmousedown=saveonmousedown;
}

I'm not sure of onfocus support with span, and how do you get focus if the mouse is disabled? Try onmouseover with an input instead:

<body onload="javascript:disablemouse();">
<form name="test">
<input onmouseover="enablemouse();" onmouseout="disablemouse();" value="you can select me" name="test1">
<input value="you cant select me" name="test2">
</form>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.