Your First App
A mobile Web app may contain many files of different types, including HTML, JavaScript, CSS, and images. You'll organize all the files that make up each Web app you create into a group called a project. To get started with your first project, follow these steps:
- Select Project > New Project.
- Choose a location for your new project that'll be easy for you to remember, such as inside your My Documents folder.
- Create a new folder inside this folder called WatzThis, and save your project inside it with the name WatzThis.
- After you save your project, you'll notice that the Projects sidebar changes to display it.
Sidebar displaying a view of your project
Now that you have your project, it's time to create your first HTML5 file.
- Select File > New > New File From Template. A New File window will appear.
- In the New File window, go to Categories and select Web. Then go to Templates, and select HTML 5.
Options in the New File window
- Type in index.html into the Filename field, and click Open. An icon representing a new file called index.html will appear inside the Projects sidebar, and the new file itself will appear in the main editing window.
Your new file, ready for you to work on
- Notice the text between <title> and </title>. This text will display at the top of your desktop browser window. Change this text to WatzThis?, as shown below:
- Insert the following three lines right after this title code to turn this webpage into a mobile webpage.
- Save your file by clicking on the disk icon in the toolbar.
Toolbar and disk icon
How does your first Web app look? Click View > Browser Preview (or Preview in Browser, depending on your operating system) to find out.
Here's your first mobile Web app! Yes, it's just a white page.
So there you have it! It's a perfect flashlight app! It loads quickly, it displays a whole lot of white screen, it'll work the same on just about any mobile device you try it on, and it uses the next generation of HTML.
If you have your own Web hosting space, you can upload your app and then try it out with a smartphone—or any mobile phone with a browser, for that matter. If you don't have Web hosting, try it out on my server—I've included a link to it in the Supplementary Material.
Note
In order for your mobile Web app to be accessible to mobile devices, you have to post it to the Internet, so people can download it. You can view and test the demonstration app in this lesson without an Internet connection or a mobile device, however.
One way to simulate the experience of using mobile Web apps on a mobile device is to resize your browser window to about the size of a mobile phone screen. (Don't worry about being precise—you can just eyeball it for now.)
Adding Some Functionality
You go back to the boss and say, "Hey, boss: I'm working on the killer app. It works on every mobile platform under the sun, it uses the latest Web technologies, and it loads extremely quickly."
He's almost giddy with excitement—and you haven't even revealed what it does yet!
The boss approves!
"I want to do some testing before I show it to you," you add. "How many days do I have to work on it before the demonstration for the investors?"
"Yes! Sounds great!" he exclaims, "I want to demo it at the shareholders' meeting tomorrow. Can you give me four or five slides demonstrating how this thing works and how to use it?"
Ugh. You hadn't considered that it might need to be something that people use. "Using" implies that it'll actually need to have some sort of interactivity.
What sort of interactivity does a flashlight have, though? Eureka! You need an On/Off button.
We'll create the button with just a little bit of JavaScript and CSS. Remember that JavaScript is a programming language that adds interactivity to Web apps. CSS is a language that adds formatting, or style, to Web apps.
By adding interactivity and style to our app, we're about to make it much more impressive.
To add your On/Off button, follow these steps:
- Start up Komodo Edit, and double-click index.html to open it.
- Insert a blank line after the three meta tags that you added earlier.
- Copy and paste the following code:
(By the way, if you ever need to add curly brackets like these { } to your document, just type [ or ] while holding down the SHIFT key.)
Now insert a blank line after the <body> tag, and copy and paste the following code:
The completed app should now look like this:
Save your file, and then preview it in your browser. You can also try this out on my server—I've included another link in the Supplementary Material.
Click the OFF button, and the screen should turn black. The screen will turn white again when you click ON. If this isn't what happens, go back to your code and make sure everything is exactly as you see above. You can recopy and repaste the whole thing to save time.
The following figure shows this app running inside a resized desktop browser.
Flashlight app with on/off switch
Not bad, right? If you're like me, you've probably already spent several minutes playing with this little gadget.
But, alas, this is hardly worth four or five slides in the boss's presentation. What good is an app if it doesn't have some advanced features?
In the next chapter, you'll add some advanced functionality to the app, and then you'll optimize it so that it looks and works better.