SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2007
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    XHTML validation error for body ondragstart and select

    Hi,

    I have this piece of js code which fails XHTML validation, can some one please externalize this code for me using JS. I am not into Javascript and actual code sample will be highly appreciated.

    <body ondragstart="return false" onselectstart="return false">

    Thank you all in advance...

    Cheers,
    Piscean

  2. #2
    In memoriam gold trophysilver trophybronze trophy Dan Schulz's Avatar
    Join Date
    May 2006
    Location
    Aurora, Illinois
    Posts
    15,495
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'd get them out of the BODY element and stick them into a separate JavaScript file which calls them through a function that targets the element directly. I'm not a JavaScript person so I can't tell you how to do that.

  3. #3
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    window.onload = function () {
    	document.body.onselectstart = function () {
    		return false;
    	}
    	
    	document.body.ondragstart = function () {
    		return false;
    	}
    }
    PS - If you are using this code to improve your UI, then great. Just don't rely on it to stop people from copying text from your page. In IE, circumventing this is as easy as typing this in address bar:
    Code:
    javascript:void(document.body.onselectstart=null);void(document.body.ondragstart=null);

  4. #4
    SitePoint Enthusiast
    Join Date
    Jun 2007
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thanks...

    Thank you Dan/ Jim for your replies...

    Jim, that was exactly what I was looking for but I am using that script to stop people from copying and I know that it is not reliable. But still the vast majority of the visitors who may not be that tech savvy will not get it.

    Thanks again!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •