Detect Safari using jQuery

前端 未结 13 1612
面向向阳花
面向向阳花 2020-11-27 10:09

Though both are Webkit based browsers, Safari urlencodes quotation marks in the URL while Chrome does not.

Therefore I need to distinguish between these two in JS.

13条回答
  •  春和景丽
    2020-11-27 10:22

    Apparently the only reliable and accepted solution would be to do feature detection like this:

    browser_treats_urls_like_safari_does = false;
    var last_location_hash = location.hash;
    location.hash = '"blah"';
    if (location.hash == '#%22blah%22')
        browser_treats_urls_like_safari_does = true;
    location.hash = last_location_hash;
    

提交回复
热议问题