stoimen.com/blog

web developing

Browser/OS detection with jQuery

As I wrote in my recent post I simply use the PPK BrowserDetect object to find out the browser/OS of the client. Actually I’m pretty sure there’s a similar jQuery plugin based again on that code from Quirksmode.org, but however I decided to write a simple plugin for jQuery wrapping it into a closure and exporting it in the “$” object.

Demo

You can see full working example here.

Installation

You must add a link to jquery.client.js after the jquery.js file in your code:

<html>
<body>
 <div id="os"></div>
 <div id="browser"></div>
 <script src="./jquery-1.3.2.js"></script>
 <script src="./jquery.client.js"></script>
 <script>
  $('#os').html("<b>" + $.client.os + "</b>");
  $('#browser').html("<b>" + $.client.browser + "</b>");
 </script>
</body>
</html>

Now there’s a $.client object containing two strings with OS and browser, they can be referenced with:

$.client.browser
$.client.os

You can append this code after you jquery.js installation. And if you’re on Firefox you simply can test with the console object:

Download

You can download the sample code from here.

  • 14 Comments
  • Filed under: javascript
  • OpenLayers disable dragging

    OpenLayers and dragging

    If working with OpenLayers you may know how the map by default is with dragging enabled. Even when in the API is said that setCenter() method is taking a forth parameter the boolean dragging it’s actually not working.

    setCenter: function(lonlat,
    	             zoom,
    	             dragging,
    	             forceZoomChange)

    As described there: Read the rest of this entry »

    javascript: get function caller

    Who calls me?

    If that’s the question a JavaScript function is asking for, and respectively you are, there is one simple way to find the answer.

    Why would I need this?

    Well let assume I’ve one function called func1, called by both func2 and func3, explained into the following example:

    Read the rest of this entry »

    Datepicker from jQuery

    You know how the jQuery UI extensions give a useful functionality for the javascript developers. The datepicker is a useful calendar tool that comes with variaty of functions.

    How to setup the selected / defaultDate

    It’s as simple as these lines of code:

    $('#element_id').datepicker({
        ...
        defaultDate : d,
        ...
    });

    The problem

    The problem is when you attach this datepicker constructor to a div which is hidden, and than you make it visible like so: Read the rest of this entry »

    ExternalInterface communication with JavaScript

    The most simple way to describe the case is as if you have the ExternalInterface addCallback in the Flex application like that:

    flex.mxml

    ExternalInterface.addCallback("jsFunc", flexFunc);
    
    public flexFunc() : void
    { ... }

    and in the javascript code you’ve something like that: Read the rest of this entry »