上QQ阅读APP看书,第一时间看更新
Displaying web pages in your app
If you need to display a live web page in your mobile app, then this recipe is for you. In this recipe, you will learn how to create a display area in your app, retrieve web data, and display that data.
How to do it...
Follow these steps to display web pages in your app:
- Create a new main stack.
- Select the stack's card and drag an image area to display the web information.
- Select the image and then select the Group icon on the toolbar to make the image a group.
- Select the group and set the following properties:
- Name:
Browser
- Width:
312
- Height:
390
- Location:
160
,225
- Name:
- At the card level, enter the following code:
local browserID
- Create a
preOpenCard
handler with the following code:on preOpenCard mobileControlCreate "browser" put the result into browserID mobileControlSet browserID, "visible", \ "true" mobileControlSet browserID, "url", \ "http://www.packtpub.com" end preOpenCard
Note
The
preOpenCard
message is sent to a card when you first go to the card and before theopenCard
message is sent. Using the onpreOpenCard
handler allows you to manipulate a card before it is visible to the user. - Create a text field to display the URL. Name the field
fld_URL
. - Next, create the following handler:
on browserFinishedLoading pURL put pURL into field "fld_URL" end browserFinishedLoading
The output is as follows:
How it works...
With only two objects and a few lines of code, we are able to retrieve and display web pages from the Internet directly in our mobile apps.