Before proceeding, make sure that you are happy with the functions in the test stack and that you have copied them to the WebScraper stack script using the following steps:
init
function:global gPageHTML,gLinks on init if the platform is "iphone" or the platform is "android" then put getLinks(gPageHTML) into gLinks if the number of lines in gLinks = 0 then answer "There are no links in this page!" else mobilePick gLinks,0 if the result > 0 then put the result into tLinkLine put line tLinkLine of gLinks into tLink go card "Browser" set the mgText of group "url" to tLink set the Text of field "NavBar" to "Browser" mobileControlSet "Page", "url", the mgText of group "url" end if end if end if end init
The card script we entered does the same job as the button in the test stack; in that, it calls to the stack functions to get a list of links. Here, rather than putting the list into a plain field, we used LiveCode's ability to open a native picker control using the line:
mobilePick gLinks,1
The required parameters of this function are a list of items to be shown and an index position to be the one that is selected. By entering 1
, the first item is selected by default. The result that comes back from the picker is an index of the item that was selected, and we can use this to look up the matching line in the gLinks
variable.
The remaining lines take us back to the Browser card, set the URL to be loaded, and also change the NavBar to reflect the card name.