Search code examples
cocoawebkit

Get webkit version in cocoa


I'm working on OSX application that needs a CSS preview. I need to find a way to differentiate users with safari 5.0 from users with safari 5.1 because webkit preview has many differences in this 2 versions. For example, the gradient radial interpretation is totally different!

Is there a way to intercept the webkit version ?


Solution

  • You can get the user-agent string for the current WebKit version using JavaScript. Just do something like this:

    NSString* userAgent = [webView stringByEvaluatingJavaScriptFromString:@"navigator.userAgent"];
    

    which will produce something like this:

    Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/534.51.14 (KHTML, like Gecko)
    

    You can then parse the user-agent string to get the version of WebKit in use.