Better way to collect data on javascript compatibility
Is there a better way to collect data on how many visitors don't have js enabled. My idea was to add a hidden value at page load with js. If it works then js w开发者_如何学编程as successful. But looks like there's no way to actually read it back to know if it was successful unless I do some kind of a page reload, but now it gets complicated (I have to delay whatever operations that were about to happen, etc. so as I said gets complicated). Any tips or ideas on this? I'm sure there's a better practice way than mine.
I should add, if there's already a ready-made solution for this, please let me know, I'm not really interested in reinventing the wheel :)
A good way to do this is use a <noscript><img src="track.php" width="1" height="1" /></noscript>
, and that will allow for browsers without javascript to pull a tracking image and then the server can get the Useragent and IP from that tracking image.
You can't know in advance which technologies the user is using client-side, so the only way to know for sure is after the first load. Even so, he might disable JS after the first page load and you're left running with a different scenario.
In fact, try it here in SO: load a page with JS enabled, then disable and reload. You'll see a big red banner at the top telling you this page works better with JS enabled.
Bottom line: you should never rely on client's technology, unless you really want to limit the people reaching your site. If you want to reach the most number of people, you should code as if they had every technology, and none at the same time.
精彩评论