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
Share on other sites

i want to be able to disable the highlighting of text everywhere, which works...

i also want to be able to activate certain tags... in that example... the div... any other ideas how i could do this?

Link to comment
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>

Link to comment
Share on other sites

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;
}

Link to comment
Share on other sites

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... ???

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.