Preventing touchmove events in a <video> element in Mobile Safari - iphone

I am writing a home-screen web app with a video element in Mobile Safari. For usability reasons, I would prefer that swiping on the screen does not make the page scroll. I can successfully prevent swipes from scrolling using the following code. However, if a user swipes on the video element, the page scrolls.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width; height=device-height; initial-scale=1.0; maximum-scale=1.0; user-scalable=no;"/>
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<title>no scroll</title>
<script type="text/javascript">
window.onload = function(){
document.addEventListener('touchmove',function(event){
event.preventDefault();
},false);
};
</script>
</head>
<body>
<p>anything but the video will be stationary when swiped.</p>
<video preload="auto" webkit-playsinline id="video" controls height="100" width="100">
<source src="video.mp4" type="video/mp4" />
</video>
</body>
</html>
I have tried adding code to prevent the video element from swallowing those events (inserted into the window.onload function):
var videoEl = document.getElementById('video');
videoEl.addEventListener('touchmove',function(event){
event.preventDefault();
},false);
videoEl.addEventListener('touchstart',function(event){
event.preventDefault();
},false);
Is there a workaround for this? Am I addressing the problem the wrong way?

I'd recommend putting a shim on top, that is, a blank div with a higher z-index to catch the touch events. I don't have a chance to test now, but should be pretty easy to try out.

Related

Responsive width for iPhone

This is my first time building a responsive site, and as I tailor the CSS for the iPhone I'm running into a problem. The styles all apply correctly, the text changes size and the wrapper changes widths. The problem is the iPhone browser still opens up at a huge width, see the screenshot:
I'm using
#media all and (max-device-width: 480px) {}
to set the specific iPhone css. body {width:;} doesn't work.
Thanks for the help :)
You have to add the following to your page header
<meta name="viewport" content="initial-scale=1.0, width=device-width" />
As in:
<!doctype html>
<html>
<head>
<title></title>
<meta name="viewport" content="initial-scale=1.0, width=device-width" />
</head>
<body>
</body>
</html>

Sencha build production can't insert meta tag

Hi Im developing a sencha-touch-2 app which will be embedded on iPhone UIWebview. The UIWebview size is 280x420 which is centered on the iPhone screen. Everything works perfect on sencha development but when I try to build the sencha into production, the size of the sencha page streched or not fit to the size of the UIWebview. Please see code below
SENCHA
Adding meta tag to the body of index.html
<body>
<meta name="viewport" content="width=device-width; initial-scale=1; maximum-scale=1;">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-touch-fullscreen" content="yes">
<div id="appLoadingIndicator">
<div></div>
<div></div>
<div></div>
</div>
</body>
This code works on development but when change to production the page change. What should I do to make it on the production build, since production is very fast on loading.
Try this, just add this script in your html body tag.
<script type="text/javascript">
setTimeout(function(){
var meta = document.createElement('meta');
meta.setAttribute("name","viewport");
meta.setAttribute("content","width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=no;");
(document.getElementsByTagName("head")[0] || document.documentElement).appendChild(meta);
},1000);
</script>
Sencha touch 2.0 will overwrite your script with it's built in meta tag. So, what happen is your meta tag will be loaded but will be replaced by it's own meta tag.

How to hide Safari Mobile browser bottom button bar in iPhone?

Following is head section:
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="apple-touch-fullscreen" content="yes" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<link rel="apple-touch-icon" href="/custom_icon.png"/>
<link rel="apple-touch-startup-image" href="/startup.png">
<script src="http://www.google.com/jsapi"></script>
<script>
window.top.scrollTo(0, 1);
alert('ok');
google.load("jquery", "1.4.1");
google.load("jqueryui", "1.8.0");
</script>
</head>
using iOS 4.2.1
Above is not working for me. Browser Address bar and bottom toolbar are still there. I have tried some tutorials but I am unable to change anything. Any idea?
For iOS 7.1, you can set this in your header to minimize the UI:
<meta name="viewport" content="width=device-width, minimal-ui">
It was introduced in iOS 7.1 beta 2. This site was instrumental in helping me understand how minimal-ui works: http://www.mobilexweb.com/blog/ios-7-1-safari-minimal-ui-bugs
You cannot programmatically hide the toolbar in Mobile Safari.
Your users need to add your web app to their home screens in order for the bars to be hidden when they next launch your app by tapping its icon. This is done by tapping the middle button in the toolbar, then choosing Add to Home Screen. You may need to display a message informing your users to do this.

jQuery mobile pages super large in Safari mobile

I'm trying to fix a display issue on my jQuery mobile site. It looks great in other browsers but when viewed on the iPhone in Safari, everything is super large and you cannot shrink the page with pinch.
For example a simple h2 element takes up most of the screen.
<meta name="viewport" content="width=device-width;
height=device-height; user-scalable=no" />
<title>Start</title>
<meta name="viewport" content="width=device-width; height=device-height; user-scalable=yes" />
<link rel="stylesheet" href="/static/css/android.css" />
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a4.1/jquery.mobile-1.0a4.1.min.css" />
<script src="https://www.google.com/jsapi?key=ABQIAAAApPeof0WyN6ORT7NeNop5OxQhS8mdepxW5-6qUjpskYmhafYcLRQjyW8D0bRdsydbD1maEkV9aSDKrw" type="text/javascript"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.js"></script>
<script type="text/javascript" src="http://code.jquery.com/mobile/1.0a4.1/jquery.mobile-1.0a4.1.min.js"></script>
<script type="text/javascript">
// Check for iPhone screen size
if($.mobile.media("screen and (min-width: 320px)")) {
// Check for iPhone4 Retina Display
if($.mobile.media("screen and (-webkit-min-device-pixel-ratio: 2)")) {
$('meta[name=viewport]').attr('content','width=device-width, user-scalable=no,initial-scale=.5, maximum-scale=.5, minimum-scale=.5');
}
}
</script>
</head>
<body>
<div data-role="page" id="start">
<div data-role="header" data-theme="a">
<h1>Start</h1>
</div><!-- /header -->
<div data-role="content" id="content">
<h2>Adventure with:</h2>
<div id="buttons">
Spam Master
CREATE NEW FOO
</div><!-- /buttons -->
</div><!-- /content -->
</div><!-- /page -->
</body>
You're almost there.
Try setting the initial-scale, that should do the trick.
<meta name="viewport" content="width=default-width, initial-scale=1" />
Related:
jQueryMobile viewport not working in Windows Phone
changing viewport based on device resolution
Hide Safari address bar and footer
jquerymobile and screen resizing
Is it possible to use jQuery to read meta tags
Having trouble using jQuery to set meta tag values
Yeah I know there is some reading to do ;)
To enable pinch: user-scalable=yes

Can Not Hiding Safari User Interface Components

I am very new for iPhone web developer.
I started with reading Safari Web Content Guide.
Then I found that we can hide user interface for example address bar of safari.
Therefore, I followed the instructor. The result is not what I expected.
The address bar still show.
I put this meta tag in html file.
and this this my code
<head>
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Hello iPhone Web App</title>
<style type="text/css">
form{
width:100%;
}
#searchBox{
font-size:25px;
width:50%;
}
#send{
font-size:25px;
}
#containerTop{
text-align:center;
width:100%;
}
</style>
</head>
<body>
<form method="get">
<div id="containerTop">
<input type="text" id="searchBox" name="search" autocapitalize="off" size="15" maxlength="128" />
<input type="submit" id="send" value="ค้นหา" />
</div>
</form>
</body>
I am looking forward to your reply, thanks
"apple-mobile-web-app-capable" only works it's magic when you launch your WebApp after having saved a link to the Home Screen, and launch your WebApp from the new icon.
For regular web pages you need to scroll the Address Bar out of view using:
<script type="text/javascript">
window.addEventListener('load', function(){ setTimeout(function(){ window.scrollTo(0,0); }, 100); }, true);
</script>
The Navigation Bar at the bottom of the screen is permanent for regular web pages, but is removable for WebApps (saved to Home Screen) using the "apple-mobile-web-app-capable" meta tag.