Humanities Home page   Office of Digital Humanities
Back     BYU LiveCode Lessons Gateway

DigHT 310
In-class Demo:
Embedding a Browser in Your Stack

LC8_widgetsAddendum 6/2017: With the advent of widgets in LiveCode 8, there is now a dead simple way to add an embedded browser to your stack. Simply drag a browser widget from the tools palette to your card, open its property inspector and add the url you want to display. As soon as you switch to run mode, the web page will be displayed in your widget!

Showing web text and graphics in your stack is all well and good, but there may be times when you just want to show a web page in your stack without worrying about whether or not LiveCode can display everything properly. LiveCode includes the revBrowser library that allows you to do just that. RevBrowser uses existing web browser engines on Mac (Safari) and Windows (Internet Explorer) to create a browser object that is displayed directly on a card in your stack.

Here is a screenshot of a stack with an embedded browser:

Embedded browser in a stack.

Although there are many ways that an embedded browser may be displayed and configured, the basic process for creating one is quite straightforward. These handlers in, say, the card script, allow you to create a basic browser object:

local browserid # declare browserID as script local variable so 
                # it can be used in both handlers 

on openBrowser
  # save the windowid in a variable for future reference
  put the windowid of this stack into tID
  # When you open a browser with the revBrowserOpen function,
  #  a unique browser ID number is generated. Thereafter
  #  whenever you do something with that browser you must 
  #  supply the browser ID, so save it in a variable.
  put revBrowserOpen(tID,fld "urlFld") into browserid
  # This is how to change properties of a browser object.
  # The syntax is
  #    revBrowserSet browser ID, property name, property setting
  revBrowserSet browserid,"rect",the rect of grc "browserOutline"
  revBrowserSet browserid,"showBorder","true"
end openBrowser

on closeBrowser
  # closing a browser is straightforward:
  revbrowserclose browserid
end closeBrowser 

All that remains now is to call openBrowser in the Open button. When you are finished with the browser, call closeBrowser. You could do this in a button or in a closeCard handler.

For more information you can take a look at a revBrowser tutorial stack produced by RunRev. It can be found in LC's Example Stacks folder. (In LiveCode, choose Help menu > Example Stacks and Resources, then look in the Examples. folder. There is also a copy in the Resources folder on the DigHT 310 file server. Or simply enter this in the LiveCode message box:

go stack URL ""

Happy LiveCode-surfing!

Back     BYU LiveCode Lessons Gateway
Maintained by Devin Asay.
Copyright © 2005 Brigham Young University.
This page last updated on June 05, 2017 17:19:49.