In jsFiddle I need to put viewport metatag in the head
element. But since jsFiddle already includes html, head and body tags, it shows a warning: "No need for the HTML tag, it's already in the output."
Is there a way to put viewport metatag in the head?
<meta name="viewport" content="width=device-width, initial-scale=1" />
The methods shown in other answers dont actually work.
The only way I have found to truly test my jsFiddles on mobile is to use php to get the fiddle content and modify it to insert the tags at the top of the
head
.This is the php script I wrote to do that:
To use this script, simply host it somewhere online and call it with your jsFiddle's url as the
url
get parameter like:http://dodsoftware.com/shared-resources/php/jsfiddle-bs-fix.php?url=http://jsfiddle.net/ivangrs/v3ajg1wx/
As previously stated by others (but hidden below the fold in the comments) none of the answers will work.
The jsfiddle embed places your code inside of an iframe. The viewport meta tag is only applied if it's on the outermost page. See this bug I filed with jsfiddle for examples: https://github.com/jsfiddle/jsfiddle-issues/issues/1094.
There is really only one solution, to host the files yourself. And if you have a place to publish an html file, then you don't really need the fiddle anymore. If you really want to bother, you simply need to add the header to your own page, then add the jsfiddle embed to that.
However, if you just want to see what it will render like on mobile on your own desktop without publishing the file yourself you can do the following:
<meta name="viewport" content="width=device-width, initial-scale=1" />
Based on the CSS panel style hack mentioned by Saturnix, I created a template on jsFiddle ready for you to fork (already with the viewport meta tag included):
http://jsfiddle.net/andreasbossard/9c3gS/
Here the code of the css for your reference:
One way to edit a jsFiddle's
head
tag is to use the CSS panelstyle
hack.Alternatively, if you're a bit more flexible and are okay with editing the viewport after the page has been loaded, you may use JavaScript or jQuery.
JavaScript
jQuery