SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Sep 2008
    Posts
    341
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    JS check if object/command supported

    I need to check if some JS is supported on a device (desktop browser or mobile, so various devices). If it is then I want to perform various further actions. Below sets a date select calendar, and I was hoping the if( $('#test').datepicker ) {} part would check if it is supported, but sometimes it fires even though it isn;t supported.

    What's the best way to check if the calendar will actually work?

    Code:
    	if (datefield.type!="date"){ //if browser doesn't support input type="date"
    	    jQuery(function($){ //on document.ready
    	        $('#test').datepicker({ dateFormat: 'dd/mm/yy' });
    	        
    	        if( $('#test').datepicker ) {        
    	       		alert("it works!");
    	   	}
    	    })
    	}
    The code is from this: http://docs.jquery.com/UI/Datepicker

    Thanks.

  2. #2
    SitePoint Addict sdleihssirhc's Avatar
    Join Date
    Feb 2009
    Posts
    387
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Just out of curiosity, what browsers are you testing that don't support the datepicker?
    I'm the web overlord for Graphic Business Systems


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
  •