Hello,
How do I check if browser supports position:fixed using jQuery. I assume I have to use $.support I think, but how?
Thank you for your time.
Hello,
How do I check if browser supports position:fixed using jQuery. I assume I have to use $.support I think, but how?
Thank you for your time.
Well, IE6 doesn't support fixed
, so you would just check $.browser.msie
and $.browser.version
with jQuery. This feature is deprecated as of 1.3 and not really recommended to use, though.
You could go down the conditional comments route:
<!--[if IE 6]>
<script src="myscripttohandleie6.js" type="text/javascript"></script>
<![endif]-->
You could check if position exists by making a code like this:
<html>
<script type="text/javascript">
test = function() {
if(!!document.getElementById("test").style.position) {
alert('true');
}
else{
alert('false');
}
}
</script>
<body>
<p id="test" onclick="test();" style="position:fixed;">Hi</p>
</body>
</html>
Since position exists in all main browser this will always return true. I imagine there isn't a way to check the possible values of position, so you'll have to check which browser and which version the user are viewing your page as Paolo Bergantino said.
The most reliable way would be to actually feature-test it. Browser sniffing is fragile and unreliable.
I have an example of such test in CFT http://yura.thinkweb2.com/cft/#IS_POSITION_FIXED_SUPPORTED. Note that the test should be run after document.body
is loaded.