SlideShare ist ein Scribd-Unternehmen logo
1 von 5
Writing a full screen mobile web app for iPhone

This is one particular post that I was trying to pen down for some time now. I believe for beginners who
are stepping into mobile web development, creating a full screen mobile web app and hiding
the address or the URL bar of the mobile browser can be a little irritating and kind of mystified at times.
In this tutorial I will discuss how to build a full screen mobile web app using pure javascript, html/html5
and css/css3. I will not be using Sencha Touch or any other mobile web frameworks here. Before reading
through, check out the demo app in an iPod or an iPhone and notice how the URL bar gets hidden to
reveal more of the viewport.

The Viewport

The main idea behind a full screen mobile web app is to hide the Address/URL bar so that the app looks
like a native app and occupies the most of the space available within the browser window. Note that we
are talking about a mobile web app and your app will run in the browser of your touch device.

Now, what is a viewport? Seems like a word that you might have heard before. Well, the actual visible
area to the user that is available for the app is the viewport. Below is an image of my iPod’s mobile safari
browser window in portrait mode. I have pointed out the labels and the sizes of each of the components.
The dimensions are same for the iPhone as well. In portrait mode the resolution is 320 x 480 pixels. You
can see from the image that in portrait mode the viewport is only 356px in height. The Status bar and
the Button bar cannot be hidden from the user and will always be displayed. So, at the best we can hide
the URL bar from the user to make the app look like a full screen app and give it a native feel.
Check out the second image below where the URL bar is hidden and the app is a full screen one. You can
see the header and footer of the web page. I have set the HTML wrapper height such that it fits the
window of the browser. Let’s talk on how to do that.
Hiding the URL bar

Whenever I am writing a mobile web app I usually place all my visual elements inside a wrapper element.
This way I can set a minimum height to my wrapper so that the app loads as a full screen. You will find out
why,

<div id="wrapper">
   <div id="header">Header</div>
   <div id="mainContent">
        <p>Eagles are members of the bird family Accipitridae,
        and belong to several genera which are not necessarily
        closely related to each other. Most of the more than
        61 species occur in Eurasia and Africa. Outside this
        area, just two species (the Bald and Golden Eagles) can
        be found in the United States and Canada, nine more
        in Central and South America, and three in Australia.
        Many different species of eagle are found in the Philippines.</p>
        <img src="images/bird.jpg" width="100%" />
   </div>
   <div id="footer">Footer</div>
</div>

Now, we need to scroll our viewport up to hide the 60 pixels URL bar. The viewport as in image1 above is
only 356px in height with the URL bar showing. If we scroll up by 60px then we need to add a 60px to
the viewport making it a 416px (356 + 60) in height. The image below will explain the process better. So
you have to set a minimum height of 416px to the HTML wrapper for the window to scroll up and hide
the address bar. This way the HTML wrapper will perfectly fit the window.
We can use standard java script methods to scroll up,

window.onload = function() {
            setTimeout(function() { window.scrollTo(0,1); }, 10);
}

You can see I have called the window.scrollTo() method inside the window load event handler. So when
the page loads, first thing it will do is to scroll up to (x=0,y=1) coordinate position. Now, a y-position of 1
ensures that the window scrolls up vertically to a point from where the viewport starts. An x-pos of 0
means that we do not want to scroll horizontally. Also I have set a timeout delay of 10ms for the
window.scrollTo() to execute. This is to trigger the vertical scrolling after the page and its elements has
been loaded up in the browser and the minimum height (416px) of the wrapper has been rendered.

All set to hide the URL bar, we need to make sure that we set a minimum height to our wrapper. You can
do this in the CSS,

#wrapper
{
    width:100%;
    height:416px;
}

Alright we have talked about the portrait mode so far. Let’s see how to do it in the landscape mode as well.
In the landscape mode the resolution becomes 480 x 320 pixels, so the height now is 320px. Check out
the image below for the dimensions,
One thing that has changed is the height of the button bar. It is 32px now wherein in portrait mode it was
44px. So the viewport height is 208px with the URL bar showing. Now, to hide the URL bar and make it
fulscreen we need to set viewport the wrapper a minimum height of (208 + 60) = 268px. So if you set
your wrapper a minimum height of 268px and use the same javascript technique to scroll up, the URL
bar will be hidden.
This is all that we need to make a full screen mobile web app. Note that I have talked of setting a
minimum height to the wrapper. If you set a height more than the minimum, which you can always do
that will also work perfectly in making it a fulscreen app. For a demo you can open this link in your iPod
or iPhone. Check the source for the full code.

Weitere ähnliche Inhalte

Kürzlich hochgeladen

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Kürzlich hochgeladen (20)

AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 

Empfohlen

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Empfohlen (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Writing a full screen mobile web app for i phone

  • 1. Writing a full screen mobile web app for iPhone This is one particular post that I was trying to pen down for some time now. I believe for beginners who are stepping into mobile web development, creating a full screen mobile web app and hiding the address or the URL bar of the mobile browser can be a little irritating and kind of mystified at times. In this tutorial I will discuss how to build a full screen mobile web app using pure javascript, html/html5 and css/css3. I will not be using Sencha Touch or any other mobile web frameworks here. Before reading through, check out the demo app in an iPod or an iPhone and notice how the URL bar gets hidden to reveal more of the viewport. The Viewport The main idea behind a full screen mobile web app is to hide the Address/URL bar so that the app looks like a native app and occupies the most of the space available within the browser window. Note that we are talking about a mobile web app and your app will run in the browser of your touch device. Now, what is a viewport? Seems like a word that you might have heard before. Well, the actual visible area to the user that is available for the app is the viewport. Below is an image of my iPod’s mobile safari browser window in portrait mode. I have pointed out the labels and the sizes of each of the components. The dimensions are same for the iPhone as well. In portrait mode the resolution is 320 x 480 pixels. You can see from the image that in portrait mode the viewport is only 356px in height. The Status bar and the Button bar cannot be hidden from the user and will always be displayed. So, at the best we can hide the URL bar from the user to make the app look like a full screen app and give it a native feel.
  • 2. Check out the second image below where the URL bar is hidden and the app is a full screen one. You can see the header and footer of the web page. I have set the HTML wrapper height such that it fits the window of the browser. Let’s talk on how to do that.
  • 3. Hiding the URL bar Whenever I am writing a mobile web app I usually place all my visual elements inside a wrapper element. This way I can set a minimum height to my wrapper so that the app loads as a full screen. You will find out why, <div id="wrapper"> <div id="header">Header</div> <div id="mainContent"> <p>Eagles are members of the bird family Accipitridae, and belong to several genera which are not necessarily closely related to each other. Most of the more than 61 species occur in Eurasia and Africa. Outside this area, just two species (the Bald and Golden Eagles) can be found in the United States and Canada, nine more in Central and South America, and three in Australia. Many different species of eagle are found in the Philippines.</p> <img src="images/bird.jpg" width="100%" /> </div> <div id="footer">Footer</div> </div> Now, we need to scroll our viewport up to hide the 60 pixels URL bar. The viewport as in image1 above is only 356px in height with the URL bar showing. If we scroll up by 60px then we need to add a 60px to the viewport making it a 416px (356 + 60) in height. The image below will explain the process better. So you have to set a minimum height of 416px to the HTML wrapper for the window to scroll up and hide the address bar. This way the HTML wrapper will perfectly fit the window.
  • 4. We can use standard java script methods to scroll up, window.onload = function() { setTimeout(function() { window.scrollTo(0,1); }, 10); } You can see I have called the window.scrollTo() method inside the window load event handler. So when the page loads, first thing it will do is to scroll up to (x=0,y=1) coordinate position. Now, a y-position of 1 ensures that the window scrolls up vertically to a point from where the viewport starts. An x-pos of 0 means that we do not want to scroll horizontally. Also I have set a timeout delay of 10ms for the window.scrollTo() to execute. This is to trigger the vertical scrolling after the page and its elements has been loaded up in the browser and the minimum height (416px) of the wrapper has been rendered. All set to hide the URL bar, we need to make sure that we set a minimum height to our wrapper. You can do this in the CSS, #wrapper { width:100%; height:416px; } Alright we have talked about the portrait mode so far. Let’s see how to do it in the landscape mode as well. In the landscape mode the resolution becomes 480 x 320 pixels, so the height now is 320px. Check out the image below for the dimensions,
  • 5. One thing that has changed is the height of the button bar. It is 32px now wherein in portrait mode it was 44px. So the viewport height is 208px with the URL bar showing. Now, to hide the URL bar and make it fulscreen we need to set viewport the wrapper a minimum height of (208 + 60) = 268px. So if you set your wrapper a minimum height of 268px and use the same javascript technique to scroll up, the URL bar will be hidden. This is all that we need to make a full screen mobile web app. Note that I have talked of setting a minimum height to the wrapper. If you set a height more than the minimum, which you can always do that will also work perfectly in making it a fulscreen app. For a demo you can open this link in your iPod or iPhone. Check the source for the full code.