Reputation: 6768
I use a range input to adjust zoom in my web application. I use some JavaScript to synchronize it with a text input next to it so users can see the value as they move the slider, and they can also type the value they want.
<input type="range" name="amountRange" min="0" max="20" value="0" onchange="this.nextElementSibling.value=this.value" />
<input type="number" name="amountInput" min="0" max="20" value="0" onchange="this.previousElementSibling.value=this.value" />
The problem is that some browsers (mainly IE9 which I want to support) are not compatible with range inputs, so the range will be displayed as a textbox. That means they will see two text-boxes like that:
<input type="text" name="amountRange" min="0" max="20" value="0" onchange="this.nextElementSibling.value=this.value" />
<input type="text" name="amountInput" min="0" max="20" value="0" onchange="this.previousElementSibling.value=this.value" />
How should I hide the range input if the browser isn't compatible with them?
Upvotes: 0
Views: 113
Reputation: 5849
You can easily handle all html browser incompatibility and use them in your advantage with modernizr.js , make sure to import the library :
<script src="https://cdnjs.cloudflare.com/ajax/libs/modernizr/2.8.3/modernizr.min.js"></script>
and then inspect your web page in IE , within the HTML tag you'll find some attribute starting with the word "no" something like no-canvas and so on, all unsupported features will start with no-HTML-or-CSS , and you can use this to apply whatever style you want .
exemple :
.no-cssreflections {
border-radius: 15px;
}
Upvotes: 1
Reputation: 8610
Javascript can feature-detect input type like so:
var rangeInput = document.forms.myformname.amountRange;
if (rangeInput.type === 'range') {
// This browser supports range.
}
else {
rangeInput.style.display 'none';
}
It seems that trying to set input.type = "somethingIEdoesntunderstand"
will actually result in an error in IE9; and all browsers will filter the possible types to what they know.
Upvotes: 1