Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

onselectstart="return false" and XHTML validation.

I want to use "onselectstart" but it's not attribute of XHTML



7:22 am on Aug 21, 2006 (gmt 0)

10+ Year Member

I want to use onselectstart="return false" to prevent copycat from copying my content. For example:

<div id="my_div" onselectstart="return false">My content</div>

It works great. The only problem is my pages are no longer valid if I use it directly. So is there a way to "capture" the on_select_start event in an external.js file? Assume the id of <div> is "my_div".

[edited by: iProgram at 7:24 am (utc) on Aug. 21, 2006]


1:02 pm on Aug 21, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

Have a look at the attachEvent [msdn.microsoft.com] method. In your case, something like this might do:

window.onload = function () { 
document.getElementById('my_div').attachEvent('onselectstart', rfalse);
function rfalse() {return false;}

Note that attachEvent and onselectstart are IE-only. In other browsers the script won't work.

[edit]fixed bugs[/edit]

[edited by: RonPK at 1:09 pm (utc) on Aug. 21, 2006]


3:15 pm on Aug 21, 2006 (gmt 0)

10+ Year Member

Thank you it works great!


1. html file

<body onload="no_sel(2)">
<div id="no_sel_0" class="no_sel">my content 1</div>
<div id="no_sel_1" class="no_sel">my content 2</div>

2. js file (IE)
function rfalse()
return false;
function no_sel(l)
for(var i=0; i<l; i++)
document.getElementById('no_sel_' + i).attachEvent('onselectstart', rfalse);

3. css file (Firefox)
That's all.


Featured Threads

Hot Threads This Week

Hot Threads This Month