How do I hide the address bar on iPhone?
I tried two different methods so far:
The scroll down one pixel trick with JavaScript on page load
And the following meta tags:
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" /><meta name="apple-mobile-web-app-capable" content="yes" />
Also this:
<meta names="apple-mobile-web-app-status-bar-style" content="black-translucent" />
I am completely confused.
PS: Oh, I forgot a really important thing: the web page itself does not overflow the browser window. It probably is the reason why the 1 pixel scrolldown trick does not work.
I can't make it bigger, since the hit thing about the design, that everyone can scroll, but this page folds... :)
I just hit this myself. If the address bar is not hiding, the reason may simply be the page is not long enough to scroll.
When the
window.scrollTo(0,1)
is called the page MUST be longer than the window so a scrolling event can occur.
Only when the scrolling even occurs will mobile safari hide the address bar.
š“ UPDATE: Apple removed support for minimal-ui in iOS 8 so this is no longer a useful answer :(
For new googlers looking into this: As of iOS 7.1 there's a new minimal-ui mode that works on mobile Safari:
It's enabled by setting the minimal-ui property on the viewport:
<meta name="viewport" content="minimal-ui">
You can also use it in conjunction with other properties like so:
<meta name="viewport" content="width=device-width, minimal-ui">
Of note, there's no minimum content length requirement as there is with the scrollTo hack. There's a great overview of this new mode here. (That's where the above image comes from.) He also lists some shortcomings.
The only official documentation I could find on this is a note in Apple's iOS 7.1 release notes:
A property, minimal-ui, has been added for the viewport meta tag key that allows minimizing the top and bottom bars on the iPhone as the page loads. While on a page using minimal-ui, tapping the top bar brings the bars back. Tapping back in the content dismisses them again.
For example, use <meta name="viewport" content="width=1024, minimal-uiā>.
Of course, since this only works in iOS 7.1 and above, it's usefulness may be limited.
Unless something has changed in recent iOS versions, the scroll down trick is the only one that reliably works, I've had no issues with this version:
/mobile/i.test(navigator.userAgent) && !location.hash && setTimeout(function() {
window.scrollTo(0, 1);
}, 1000);ā
I didn't care about any other mobile platform for this particular page though, it was redirecting based on agent...you may want to change the regex to check for iPhone specifically, e.g. replace /mobile/ with /iPhone/.
I think this version is actually better. It tests to see if the user has already begun scrolling, which is an issue I noticed in my mobile project.
/Mobile/.test(navigator.userAgent) && !location.hash && setTimeout(function () {
if (!pageYOffset) window.scrollTo(0, 1);
}, 1000);
You can run the function when the site content is ready instead of using timeout
addEventListener("load", function() {
window.scrollTo(1, 0);
}, false);
Try:
setTimeout(function () {
window.scrollTo(0, 1);
}, 1000);
If using jQuery, put it at the end of $(document).ready();. The time-out allows for the browser to determine the height of the page...
In case none of these solutions work and you are running into the very narrow issue that I faced, here's what fixed it for me.
I had this in my CSS
html{position: relative; height: 100%; overflow: hidden;}
This css applies a fix to one of my pages only, so I restricted it with a condition to that page, and the address bar is now behaving correctly on all other pages.
I have been searching around on this full screen web app as well and i found this.
http://www.onlywebpro.com/2015/07/19/optimizing-full-screen-mobile-web-app-for-ios/
Basically you need add the following in your header:
<meta name="viewport" content = "width = device-width, initial-scale = 1.0, minimum-scale = 1, maximum-scale = 1, user-scalable = no" />
//App name
<meta name="apple-mobile-web-app-title" content="App name" />
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
//APP ICONS
<link rel="apple-touch-icon" href="/img/icon.png">
<link rel="apple-touch-icon" sizes="76x76" href="/img/icon.png">
<link rel="apple-touch-icon" sizes="120x120" href="/img/icon.png">
<link rel="apple-touch-icon" sizes="152x152" href="/img/icon.png">
Open the site in Safari
Tap on the "Open with" icon ( arrow pointing upwards and box below it) beside refresh button at the URL bar
Select "Add to home screen"
Go to the homescreen and open the "App name"
Voila! website with no URL bar or navigation buttons!
<meta name="apple-mobile-web-app-capable" content="yes" />
iPhone Configuring Web Applications
I think it will never be solved unless the content is more than the browser window.
Here is some code that will hide the URL on load, on orientation change, and on a touchstart (the touchstart should only be used if you have a persistent hidden URL, which is a whole other can of worms - if you don't, remove that part of the script).
if( !window.location.hash && window.addEventListener ){
window.addEventListener("load", function() {
setTimeout(function(){
window.scrollTo(0, 0);
}, 0);
});
window.addEventListener( "orientationchange",function() {
setTimeout(function(){
window.scrollTo(0, 0);
}, 0);
});
window.addEventListener( "touchstart",function() {
setTimeout(function(){
window.scrollTo(0, 0);
}, 0);
});
}
<meta charset="utf-8"><meta name="description" content="{MF_PLUGIN_SETTING:HOME_DESCRIPTION}"/><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1"/><meta name="apple-mobile-web-app-capable" content="yes"><meta name="mobile-web-app-capable" content="yes">
This is used for adding a ios web app to the homescreen without the searchbar.
Related
IĀ“m trying to modify the scale of a page load in a WKWebView. It is working as far as IĀ“m looking in the html. But the actual scale in the WKWebview doesnĀ“t change.
HereĀ“s how I inject the script:
let script =
"var viewport = document.querySelector(\"meta[name=viewport]\");" +
"viewport.setAttribute('content', 'width=device-width, initial-scale=0.4, user-scalable=0');" +
let userScript = WKUserScript(source: script,
injectionTime: WKUserScriptInjectionTime.atDocumentEnd,
forMainFrameOnly: true)
userContentController.addUserScript(userScript)
Print the html:
webView.evaluateJavaScript("document.getElementsByTagName('html')[0].innerHTML", completionHandler: { (innerHTML, error) in
print(innerHTML)
})
HTML result in console:
Optional(<!--<![endif]--><head>
<title>Bitcoin (BTC) $2391.84 (1.85%) | CoinMarketCap</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=0.4, user-scalable=0">
<meta name="google-site-verification" content="EDc1reqlQ-zAgeRrrgAxRXNK-Zs9JgpE9a0wdaoSO9A">
<meta property="og:type" content="website">
IĀ“m asking myself if this is the right approach. I also tried: let script = document.body.style.zoom = '0.8'; and let script = document.body.style.webkitTransform = 'scale(0.8)'; which is both working in terms of scale, but using this method, the timeperiod slider in this highchart loses its functionality. Any kind of new ideas would be much appreciated.
Add <meta name="viewport" content="width=device-width, shrink-to-fit=YES"> to your HTML file.
(I added right after but not sure if you can add it anywhere)
In my case I have html files for privacy in my Xcode project. I added that javascript code right below the and it did the trick for me.
It works as if you used scalePageToFit in UIWebView.
Hope it helps.
I want to dynamically change meta tag viewport in "index.html" in windows phonegap app on button click.
I am using
Windows OS 8
phonegap 3.5
Device Nokia Lumia 1320 with windows 8 OS
I want to change below meta tag
<meta id="viewport" name="viewport" content="width=device-width">
to
<meta id="viewport" name="viewport" content="width=720">
I have already tried below URLs but nothing worked for windows phone.
how to set viewport so it is 380x800 or 800x380 depending on orientation?
Setting the Viewport to Scale to Fit Both Width and Height
Here I found link where it says it is not possible to change meta tag dynamically in winodws 8 OS
http://www.quirksmode.org/blog/archives/2011/06/dynamically_cha.html
Try to detect the device/OS and change the meta tag accordingly http://www.sitepoint.com/detect-mobile-devices-jquery/
1st write simple function JavaScript for example I have written one function viewport()
<html>
<head>
<script>
function viewport(){
var msViewportStyle = document.createElement("style");
msViewportStyle.appendChild(
document.createTextNode(
"#-ms-viewport{width:auto!important;zoom:1!important;}"
)
);
msViewportStyle.appendChild(
document.createTextNode(
"#-ms-viewport{height:auto!important}"
)
);
document.getElementsByTagName("head[0].appendChild(msViewportStyle);
}
</script>
</head>
<body>
<button id="btnSubmit" onclick="viewport();">changeviewport</button>
</body>
more..[1]:Can I change the viewport meta tag in mobile safari on the fly?
I have a Twitter bootstrap 3 site, it works well except Android 2.3 browsers.
In my fixed navbar I have a button that opens a div (collapsible) and a list of links appear. But in Android 2.3 list is opened, but all list is not visible, only the half of them visible. Scrollbar doesn't appear and touching the menu doesn't respond.
So after some research I started to use iScroll 5. But Scrolling doesn't work when the page loaded. iScroll works when I flip device to landscape and then back to portrait.
<script type="text/javascript" src="/scripts/iscroll.js"></script>
<div class="my_polyfill">
<ul>
<li>...</li>
<li>...</li>
...
</ul>
</div>
I added viewport:
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no">
I added a timeout like this:
$(window).load(function() {
setTimeout( function() { var myScroll = new IScroll('.my_polyfill'); }, 4000);
}
But still iScroll works when I make a portrait-landscape-portrait flip. How can I fix this ? Or debug the problem.
add myScroll.refresh() once your page is done rendering.
I'm new with jquery. I tried to detect browser size using the following code and tried various ways but it alerts yay whenever the browser is resized. I checked online and I couldn't figure out what went wrong with my code. Would anyone know why? I'm trying to detect the size so I could disable the area tag link on the image on mobile screen.
$(window).ready(function() {
$(window).resize(function() {
var wi=$(window).width();
var he=$(window).height();
if ((wi<=480) && (he<=568))
{
alert('yay');
}
});
});
use event if you want runtime resize it
$(window).resize(function(event) {
var wi=$(window).width();
var he=$(window).height();
if ((wi<=480) && (he<=568))
{
alert('yay');
}
});
and if you want make style for mobile you must create code in <head> like:
<meta name="viewport" content="width=device-width, height=device-height" />
<link id="stylesheet-tablet" media="(min-width: 0px) and (max-width: 480px)" href="mobile.css" type="text/css" rel="stylesheet">
or use percent size
.wraper{width:100%;}
.wraper .child{width:50%}
or you can use bootstrapt UI Framework
I want to use a custom keyboard for UIWebView. Custom keyboard should be all HTML/JS/CSS in order to use for multiple device. For this reason I added a notification like bellow:
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardWillShow) name:UIKeyboardWillShowNotification object:nil];
In order to not allow the natural keyboard to comes up, I added following method when the notification is called.
- (void)keyboardWillShow
{
[self.webViews endEditing:YES];
}
In HTML file I have:
<!DOCTYPE>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>keyboard</title>
<link rel="stylesheet" type="text/css" href="css/style.css" />
</head>
<body>
<div id="container">
<textarea id="write"></textarea>
</div>
</body>
</html>
The problem is, when I run this HTML file in UIWebView and have longpress on textarea, or double tap, it crashes the application.
If I remove [self.webViews endEditing:YES]; It won't crash the app but it brings up the keyboard.
I suspected to "copy/paste/select All" options on UIWebView when the user double tap or long press on textarea. I tried to disable them but it didn't work.
Any idea would be appreciated.
Customizing the keyboard needs a different approach.
There's a good explanation here including some code examples:
Customizing the iOS keyboard
There's another thread here on SO with some discussion and links on the subject:
How to create a custom keyboard
This is Apple Bug #15535639, I hope they fix it soon.
Try this workaround, it worked for me.
- (void)keyboardWillShow
{
dispatch_async(dispatch_get_main_queue(), ^{
[self.webViews endEditing:YES];
});
}