Page 1 of 1
WebBrowser Help
Posted: Fri Mar 02, 2012 5:16 pm
by Filigrano
Hello,
i'd like to make a little web browser in livecode. i already looked at the example but i don't understand it
can you help me?
greetz
Re: WebBrowser Help
Posted: Fri Mar 02, 2012 5:28 pm
by sturgis
A quick synposis..
revbrowseropen is used to create a browser instance.
put revbrowseropen(the windowid of this stack,"
http://www.google.com") into sBrowserId
This will create a browser instance attached to the stack that contains the script, and set its url to "
http://www.google.com" and put the browser instance id into the script variable sBrowserId You will want to declare sBrowserId as a script local variable so that it is persistent.
At this point you have a browser instance created but you can't see it yet. You need to set the area to display the browser.
revbrowserset sBrowserId,"rect","10,10,200,200" -- will set the rectanble of the browser instance (based on sBrowserId) to 10,10,200,200
Look in the dictionary for more stuff relating to browser, revbrowser, revbrowsernavigate, revbrowserget, revbrowserset etc.
If you need to make sure you haven't started multiple browser instances, look at revbrowserinstances in the dictionary.
To close an instance look at revbrowserclose in the dictionary
Once you start to understand a little better how revbrowser works, look back at the sample and see if you understand it better. If not, maybe ask more specific questions about the parts you don't understand so its easier to respond.
Re: WebBrowser Help
Posted: Fri Mar 02, 2012 5:31 pm
by Filigrano
arrgh, thanks
can i run the browser also in the background?
Re: WebBrowser Help
Posted: Fri Mar 02, 2012 5:35 pm
by sturgis
It can be hidden or shown yeah. Look at revbrowserset. The revbrowser will still be attached to the stack you designate, but yuo can set the visible property to true or false for the browser instance.
revbrowserset sBrowserId,"visible",true-- shows the browser, set to false to hide
Re: WebBrowser Help
Posted: Fri Mar 02, 2012 5:37 pm
by Filigrano
ok thanks

Re: WebBrowser Help
Posted: Fri Mar 02, 2012 5:45 pm
by Filigrano
next question.... where i write it in? i mean the code you posted.

Re: WebBrowser Help
Posted: Fri Mar 02, 2012 5:55 pm
by sturgis
Probably the easiest place is the card script. If you only need to worry about 1 instance of the browser you can put all your handlers in the card script.
Usually, if i'm setting one up to display a specific site (without popups, multiple pages showing or anything too complex) I declare sBrowserID as a local var at the top of the card script.
Then I make a startBrowser handler that does the revbrowseropen, checks for errors, and if there are no errors it sets sBrowserId, and calls another handler that sets the position of the browser instance. If there was a problem starting the browser instance an error message is displayed. I usually only want 1 instance open at a time so I make sure that there aren't already running instances.
I also create a stopBrowser handler to close the browserinstance.
Another one to handle navigation requests..
If I need to be able to set the contents of the displayed page (for help pages for my app as an example) I have another handler that will set the htmltext of the instance using revbrowserset
If I am scraping pages I have yet another handler that will get the htmltext of the instance (using revbrowserget)
Re: WebBrowser Help
Posted: Sun Mar 04, 2012 1:16 pm
by Filigrano
where is the mistake?!
nothing on the card!
Re: WebBrowser Help
Posted: Sun Mar 04, 2012 2:25 pm
by sturgis
Change it to
put revbrowseropen(the windowid of this stack,"
http://www.google.com") into tBrowserId
After you do revbrowseropen you need to check the contents of tBrowserId
if tBrowserId is an integer then
-- the browser opened ok, do your stuff
else
-- the browser did NOT open ok, display an error message
end if
Also, you'll want to watch for multiple instances of the same browser, so your open card handler can do a check for the contents of tBrowserId
if tBrowserId is not an integer then
-- start the browser
else
-- don't start the browser
end if
The reason "the windowid of me" doesn't work is because "of me" in this case refers to the CARD not the stack. windowid is not a card property, its a stack property.
Also, while its probably obvious, once your code is entered and compiled since its an 'opencard' handler that you're using to start the browser, you'll either have to change cards and then come back to this one, or close and re-open the stack, or easiest.. use the message box and run the opencard handler from there to get the handler to fire.
It might be better to separate things out into separate handlers also. A handler to start the browser instance, another to stop it and clear tBrowserId, another to resize the browser (so that when the stack is resized it can be used to resize the browser instance on the fly)