Created
August 29, 2013 12:45
-
-
Save RavisMsk/6377617 to your computer and use it in GitHub Desktop.
Scale UIWebView contents to view width using javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[_webView stringByEvaluatingJavaScriptFromString: | |
[NSString stringWithFormat:@"var result = '';" | |
"var viewport = null;" | |
"var content = null;" | |
"var document_head = document.getElementsByTagName( 'head' )[0];" | |
"var child = document_head.firstChild;" | |
"while ( child )" | |
"{" | |
" if ( null == viewport && child.nodeType == 1 && child.nodeName == 'META' && child.getAttribute( 'name' ) == 'viewport' )" | |
" {" | |
" viewport = child;" | |
" viewport.setAttribute( 'content' , 'width=270;initial-scale=1.0' );" | |
" result = 'fixed meta tag';" | |
" }" | |
" child = child.nextSibling;" | |
"}" | |
"if (null == viewport)" | |
"{" | |
" var meta = document.createElement( 'meta' );" | |
" meta.setAttribute( 'name' , 'viewport' );" | |
" meta.setAttribute( 'content' , 'width=device-width;initial-scale=1.0' );" | |
" document_head.appendChild( meta );" | |
" result = 'added meta tag';" | |
"}" | |
] | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment