HI chaps, I was wondering if it is possible to add a meta tag using jquery to an html page before the page loads.
The reason why I ask, is because I have a page with no viewport meta tag on and it should have it only when the resolution drops below 700px - <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1"/>
Well I guess that would be possible :). Maybe something like:
// Do your width checks etc. here, check out the jQuery website for more info.
if(page_width < 700)
// Create <meta> tag.
$('head').append('<meta name="bla" content="test">');
// Remove the <meta> tag.
thanks, but doesn't the above happen when the page has arleady loaded ? I am not entirely sure how the page evaluates meta tag, I assume it does it before the page load. So what I want ideally is to have the browser to determine the resolution or page width (say I am browsing the site from a mobile device) and if so loads the meta tag and therefore adapt the page to the device
thanks, unfortunately I need the meta tag to be added before the page loads - if it is possible at all.
Yes I am using media queries already, the reason why I wanted to add the meta tag on the fly is because I need a way for the browser to follow these content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1 once the widt has been determined, and I don't know if I can do that with media queries
What you can do on the fly is $('head').append('<meta name="bla" content="test">'); :). If you don't put that in a $(document).ready(), then it will be executed while the page is being generated. E.g. if you put it between your <head> and </head> tags, the <meta> tag is created before your browser even parses the </head> tag, for as far as my knowledge goes.
Ok I see, but am I right to suspect that each browser might implement it in a different way, as in some might not parse that js on time to assign the metatag before the page is load, in other words, is this guaranteed to work on every browser (including mobile ones?) as long as js is enabled?