I used the following jquery to insert a metatag into a html document.
<script type="text/javascript">
if(screen.width>=320 && screen.width<=767){
$('head').append('<meta id="viewport" name="viewport" content="width=320; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">');}
</script>
If possible, I'd like to insert the metatag without using jquery. Anyone have any ideas how I can do that?
I believe I will probably need to use document.getElementByTagName but I'm not sure how.
Just in case you are wondering, I am inserting the metatag into my html to to optomize the site for viewing with the iphone. Unfortunately, width=device-width is not an option as it doesn't play well with my ipad version.
You can also use "setAttribute" (rather than the "dot" notation) for weirdo attribute names (that contain non-alpha-numeric characters).
Example:
The example above causes IE (<=9) to always use the latest document standards mode. Sometimes IE will fall back to older standards, and therefore break your modern javascript / canvas web app.
Here is a solution that creates a meta tag, if it does not already exist:
Javascript solution: