Accessing the Internet There are a number of ways to access the Internet from LiveCode programs. The easiest is using the "Launch" command. It runs (launches) the default application on your computer (e.g. I.E., Safari, etc) then transferring control to it. We did this in the last lesson. The better way (but more difficult one) is by creating your own browser window inside of LiveCode. You stay inside of your Livecode application and have full control over what the user does. This will open up a url in your default browser (another window). So if your default browser is FireFox, then it will open up a new window with firefox in it. This works well on a desktop computer but not so well on a mobile computer (cell phone, tablet). Each launch command opens up a new window. On a desktop, most people have more than one window open at a time but how many windows can you open on a small cellphone? The other disadvantage of doing it this way is that you leave your program and you are not in control any more. Accessing the Internet (using the Launch command with a url address) You can access the Internet from within LiveCode by using the Launch command with URL specified e.g. launch url "http://www.livecode.com" Ask the user for the url: Create a button and add this to the script: on mouseUp ask "What is the Internet address to go to?" put it into myurl launch url "http://" & myurl end mouseUp It will pop-up a dialog box asking the user for an Internet address, then open it up in a browser window.
2. Accessing the Internet - Internally in LiveCode (in a browser window, Desktop and Mobile) If you want to keep everything inside your app (without going to another program), you can use a browser window (revBrowser object). This works well in either a desktop or a mobile computer. The advantage of this is that you stay within your own program or app. You open a "browser" window on your card, and go to the web address. When done, you have to close that "browser" window. It is tricky only because you have to write code to prevent errors and be very careful how and where you issue the commands. (You get errors if you do not do things in the right sequence or try to open 2 browsers with the same "ID".) First you need to initialize the revBrowser. It only has to be done once. (Just as you open up a normal browser - IE, FireFox, Safari, Chrome- and just use that one, to visit different sites). Most of the time, we put this in the openCard handler that runs when you first open the card. a. Initializing the Browser Object (Window) First create an image area for the browser window using the "image Area Tool" and size it on your card. Name it "browser image" -----------Put this code on the Card Script --------------------------------
-----------Put this code on the Card Script -------------------------------- b. Showing the webpage
C. Add code for the mobile platforms global myBrowser if the environment is "mobile" then note: if you are using version 6.7 or higher of LiveCode on closeCard For more examples of what you can do with revBrowser there is a Browser Sampler stack in the Resources/Examples folder of your Rev distribution. You might also find the Explore LiveCode: The Internet tutorial interesting 3. If you are developing a program that is running on a mobile device, then have a look at this lesson: http://lessons.runrev.com/s/lessons/m/4069/l/22836 old: revBrowser is only supported on desktop platforms. You can view PDF files from the Internet on iOS using Browser Control. Check out this lesson on how to do it: http://lessons.runrev.com/s/lessons/m/4069/l/22836-How-do-I-use-the-Browser-Control- Advanced Coding: Another Way with more detail and checks: Here, you may just want to have separate buttons to open and close a browser window and others to go to specific websites: There are a set of commands to create and work within a browser window in LiveCode Lets build a desktop browser: 1. Open a new Main Stack Add the following handlers to your card or stack:
After you open a browser window, to open a website use the following code: put revBrowserOpen(the windowId of this stack, "http://www.msn.com") into xBrowser Dont forget to close it when you are finished 2 Single Use Websites on openMSN put revBrowserOpen(the windowId of this stack, "http://www.msn.com") into xBrowser revBrowserSet xBrowser, "visible", true revBrowserSet xBrowser, "rect", the rect of graphic "template" --revBrowserClose xBrowser end openMSN |
Home >

