I want to use rev Browser and call and open within a stack various html files that reside on the local computer, not on the Internet. I’ve been able to do this only by hard coding the exact file path / filename in the Custom Properties of the browser stack. I’m looking for code that can be used to open an html file in a revBrowser according to a relative path specification. I found no way of doing this using the altHomeURL property of the Custom Properties of the browser stack. Following is the code that opens a file using the hard coded path / filename:
–––––––––––––––––––––––––––––––––––––––––––
on openstack
toggleControls "on"
send "initAltBrowser" to this card in 1 second
end openstack
on initAltBrowser
abOpenBrowser the altHomeURL of this stack
revBrowserSet the altBrowserId of this stack, "showborder", true
revBrowserSet the altBrowserId of this stack, "rect", the rect of image "BrowserArea"
revBrowserRedraw the altBrowserId of this stack
end initAltBrowser
–––––––––––––––––––––––––––––––––––––––––––
The line “abOpenBrowser the altHomeURL of this stack” in the above code opens the revBrowser and opens in it the hard coded file. The value of the altHomeURL is what is placed in the property of the Custom Properties of the browser stack. This is limiting and inflexible.
Is there an alternative more flexible way to do this for multiple files and relative file paths that can be selected by the user, from, say, a picklist and using variables? Any assistance or reference to a good source of documentation or sample code for such would be greatly appreciated.
Calling local html files in revBrowser using a relative path
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Re: Calling local html files in revBrowser using a relative path
Hi mebtrek,
you can always set this custom property to any value you like BEFORE you open the brwoser!
And since I am not sure if the Brwoser supplies relative urls, I would create an asbolute filepath:
This is out of my head, but you should get the picture.
BTW, looks like you have a VERY old example stack from the time when the Browser
external was NOT YET part of LiveCode!
It was created sold by Chipp Walters company Altuit (the "alt" in "altbrowser")
Remember that you can INIT the browser WITHOUT having to open an URL!
You can SET this URL later.
Best
Klaus
you can always set this custom property to any value you like BEFORE you open the brwoser!
And since I am not sure if the Brwoser supplies relative urls, I would create an asbolute filepath:
Code: Select all
on openstack
toggleControls "on"
## Creat an abolute path and put it into that custom property
put the effective filename of this stack into tFile
set itemdel to "/"
## supposed you have a folder "html" in the folder with your stack
put "html/your_local_html_file_here.html" into item -1 of tFile
put "file://" before tFile
set the altHomeURL of this stack to tFile
send "initAltBrowser" to this card in 1 second
end openstack
BTW, looks like you have a VERY old example stack from the time when the Browser
external was NOT YET part of LiveCode!

It was created sold by Chipp Walters company Altuit (the "alt" in "altbrowser")
Remember that you can INIT the browser WITHOUT having to open an URL!
You can SET this URL later.
Best
Klaus
Re: Calling local html files in revBrowser using a relative path
Klaus,
Thank you very much!
I'll play around with those suggestions and report back for the benefit of all. Meanwhile, since you indicated that the code I was using is outdated from when the Browser external was not yet part of LiveCode, can you post or send me directly at mebtrek@yahoo.com a more current overal revBrowser sample stack to work with. I'm yet far from expert level so that would be very helpful at this time.
Al
Thank you very much!
I'll play around with those suggestions and report back for the benefit of all. Meanwhile, since you indicated that the code I was using is outdated from when the Browser external was not yet part of LiveCode, can you post or send me directly at mebtrek@yahoo.com a more current overal revBrowser sample stack to work with. I'm yet far from expert level so that would be very helpful at this time.
Al
Re: Calling local html files in revBrowser using a relative path
All,
Got it to work using suggestion from Klaus. Following is the code, albeit very old code except for the modifications made in on openstack, Thank you Klaus.
Note: The local html file being opened is in a folder named "Called Files" in the directory containing the .rev file. The file name is "HTML-01.html"
Finally, if anyone has better more updated code for revBrowser, please advise. Thanks.
on openstack
toggleControls "on"
put the effective filename of this stack into tFile
set itemdel to "/"
put "Called Files/HTML-01.html" into item -1 of tFile
put "file://" before tFile
set the altHomeURL of this stack to tFile
send "initAltBrowser" to this card in 1 second
end openstack
on initAltBrowser
abOpenBrowser the altHomeURL of this stack
revBrowserSet the altBrowserId of this stack, "showborder", true
revBrowserSet the altBrowserId of this stack, "rect", the rect of image "BrowserArea"
revBrowserRedraw the altBrowserId of this stack
end initAltBrowser
on resizeStack
local tRect
put the rect of this card into tRect
set the width of field "FileAddress" to width of this card - 114
set the width of grc "topBack" to width of this card
set the width of btn "bDiv1" to width of this card
set the width of btn "bDiv2" to width of this card
set the width of btn "bDiv3" to width of this card
set the right of img "busy.gif" to the width of this card
set the right of btn "GO" to the width of this card -10
set rect of field "logfield" to 2, item 4 of tRect-22, item 3 of tRect-2, item 4 of tRect-2
get the rect of image "BrowserArea"
set the rect of image "BrowserArea" to 5, item 2 of it,item 3 of trect-5,item 4 of trect-26
-- OK-2007-11-23 : Bug 5445
if the altBrowserId of this stack is among the items of revBrowserInstances() then
revBrowserSet the altBrowserId of this stack, "rect", the rect of image "BrowserArea"
end if
end resizeStack
on closeStackRequest
local tBrowserId
put the altBrowserID of this stack into tBrowserId
if tBrowserId is among the items of revBrowserInstances() then
revBrowserClose tBrowserId
end if
set the altBrowserID of this stack to empty
close this stack
end closeStackRequest
on closeCard
end closeCard
on toggleControls pState
if pState is "off" then
disable btn "Back"
disable btn "Forward"
disable btn "Refresh"
disable fld "FileAddress"
else
enable btn "Back"
enable btn "Forward"
enable btn "Refresh"
enable fld "FileAddress"
end if
end toggleControls
on abSuspendBrowser
if the altBrowserId of this stack is not among the items of revBrowserInstances() then
exit abSuspendBrowser
end if
local tCurrentUrl
if the altBrowserState of this stack is true then
put revBrowserGet(the altBrowserId of this stack, "url") into tCurrentUrl
set the altCurrURL of this stack to tCurrentUrl
revBrowserClose the altBrowserId of this stack
toggleControls "off"
end if
end abSuspendBrowser
on abResumeBrowser
if the altBrowserState of this stack is true then
abOpenBrowser the altCurrURL of this stack
revBrowserSet the altBrowserId of this stack, "rect", the rect of image "BrowserArea" of this stack
revBrowserSet the altBrowserId of this stack, "newwindow", false
revBrowserSet the altBrowserId of this stack, "visible", true
revBrowserSet the altBrowserId of this stack, "showborder", true
abLoadURL the altCurrURL of this stack
toggleControls "on"
end if
end abResumeBrowser
on abLoadURL pURL
local tPrefix
put char 1 to 6 of pURL into tPrefix
switch tPrefix
case "http:/"
case "file:/"
case "https:"
break
case "ftp://"
if the platform is "MacOS" then
answer "Sorry, Safari browser won't do FTP
"
exit to top
end if
break
default
put "http://" before pURL
put pURL into fld "FileAddress" of stack "Viewer Window_Html"
break
end switch
if the altBrowserState of this stack is true then
revBrowserSet the altBrowserId of this stack, "url", pUrl
else
initAltBrowser
end if
set the altCurrURL of this stack to pURL
end abLoadURL
on abOpenBrowser pURL
local tWindowId
put the windowid of this stack into tWindowId
local tBrowserId
put revBrowserOpen(tWindowId, pUrl) into tBrowserId
if tBrowserID contains "error" or tBrowserId is not an integer then
answer warning tBrowserId
exit to top
end if
set the altBrowserID of this stack to tBrowserId
end abOpenBrowser
on abIamBusy
set the repeatcount of img "busy.gif" to -1
put "Accessing page:" && the altCurrURL of this stack into fld "logfield" of this stack
end abIamBusy
on abIamNotBusy
set the repeatcount of img "busy.gif" to 0
set the currentframe of img "busy.gif" to 1
put "Finished" into fld "logfield" of this stack
end abIamNotBusy
on browserClosing pId
end browserClosing
on browserNewUrlWindow pId, pUrl
answer "link trying to open in new window:"&cr&pURL
revBrowserSet pId, "url", pUrl
end browserNewUrlWindow
on browserNavigateComplete pId, pUrl
end browserNavigateComplete
on browserBeforeNavigate pId, pUrl
abIamBusy
global browserCancel
if pURL contains "xxx.com" then
abIamNotBusy
answer warning "Won't allow you to go to domain xxx.com! See XBrowser_BeforeNavigate!"
put true into browserCancel
end if
end browserBeforeNavigate
on browserNavigateCompleteFrame pId, pUrl
end browserNavigateCompleteFrame
on browserBeforeNavigateFrame pId, pUrl
abIamBusy
end browserBeforeNavigateFrame
on browserDocumentComplete pId, pUrl
abIamNotBusy
put pURL into fld "FileAddress" of this stack
local tUrl
put fld "FileAddress" into tUrl
set the altCurrURL of this stack to tUrl
end browserDocumentComplete
on browserDocumentCompleteFrame pId, pUrl
abIamNotBusy
put pURL into fld "FileAddress" of this stack
local tUrl
put fld "FileAddress" of this stack into tUrl
set the altCurrURL of this stack to tUrl
end browserDocumentCompleteFrame
on browserDownloadRequest pId, pUrl
answer information "The browser is attempting to download the file: " & return & pURL & return & return & "Please handle this in the 'DownloadRequest' callback'"
abIamNotBusy
#revBrowserStop the altBrowserId of this stack
end browserDownloadRequest
Got it to work using suggestion from Klaus. Following is the code, albeit very old code except for the modifications made in on openstack, Thank you Klaus.
Note: The local html file being opened is in a folder named "Called Files" in the directory containing the .rev file. The file name is "HTML-01.html"
Finally, if anyone has better more updated code for revBrowser, please advise. Thanks.
on openstack
toggleControls "on"
put the effective filename of this stack into tFile
set itemdel to "/"
put "Called Files/HTML-01.html" into item -1 of tFile
put "file://" before tFile
set the altHomeURL of this stack to tFile
send "initAltBrowser" to this card in 1 second
end openstack
on initAltBrowser
abOpenBrowser the altHomeURL of this stack
revBrowserSet the altBrowserId of this stack, "showborder", true
revBrowserSet the altBrowserId of this stack, "rect", the rect of image "BrowserArea"
revBrowserRedraw the altBrowserId of this stack
end initAltBrowser
on resizeStack
local tRect
put the rect of this card into tRect
set the width of field "FileAddress" to width of this card - 114
set the width of grc "topBack" to width of this card
set the width of btn "bDiv1" to width of this card
set the width of btn "bDiv2" to width of this card
set the width of btn "bDiv3" to width of this card
set the right of img "busy.gif" to the width of this card
set the right of btn "GO" to the width of this card -10
set rect of field "logfield" to 2, item 4 of tRect-22, item 3 of tRect-2, item 4 of tRect-2
get the rect of image "BrowserArea"
set the rect of image "BrowserArea" to 5, item 2 of it,item 3 of trect-5,item 4 of trect-26
-- OK-2007-11-23 : Bug 5445
if the altBrowserId of this stack is among the items of revBrowserInstances() then
revBrowserSet the altBrowserId of this stack, "rect", the rect of image "BrowserArea"
end if
end resizeStack
on closeStackRequest
local tBrowserId
put the altBrowserID of this stack into tBrowserId
if tBrowserId is among the items of revBrowserInstances() then
revBrowserClose tBrowserId
end if
set the altBrowserID of this stack to empty
close this stack
end closeStackRequest
on closeCard
end closeCard
on toggleControls pState
if pState is "off" then
disable btn "Back"
disable btn "Forward"
disable btn "Refresh"
disable fld "FileAddress"
else
enable btn "Back"
enable btn "Forward"
enable btn "Refresh"
enable fld "FileAddress"
end if
end toggleControls
on abSuspendBrowser
if the altBrowserId of this stack is not among the items of revBrowserInstances() then
exit abSuspendBrowser
end if
local tCurrentUrl
if the altBrowserState of this stack is true then
put revBrowserGet(the altBrowserId of this stack, "url") into tCurrentUrl
set the altCurrURL of this stack to tCurrentUrl
revBrowserClose the altBrowserId of this stack
toggleControls "off"
end if
end abSuspendBrowser
on abResumeBrowser
if the altBrowserState of this stack is true then
abOpenBrowser the altCurrURL of this stack
revBrowserSet the altBrowserId of this stack, "rect", the rect of image "BrowserArea" of this stack
revBrowserSet the altBrowserId of this stack, "newwindow", false
revBrowserSet the altBrowserId of this stack, "visible", true
revBrowserSet the altBrowserId of this stack, "showborder", true
abLoadURL the altCurrURL of this stack
toggleControls "on"
end if
end abResumeBrowser
on abLoadURL pURL
local tPrefix
put char 1 to 6 of pURL into tPrefix
switch tPrefix
case "http:/"
case "file:/"
case "https:"
break
case "ftp://"
if the platform is "MacOS" then
answer "Sorry, Safari browser won't do FTP

exit to top
end if
break
default
put "http://" before pURL
put pURL into fld "FileAddress" of stack "Viewer Window_Html"
break
end switch
if the altBrowserState of this stack is true then
revBrowserSet the altBrowserId of this stack, "url", pUrl
else
initAltBrowser
end if
set the altCurrURL of this stack to pURL
end abLoadURL
on abOpenBrowser pURL
local tWindowId
put the windowid of this stack into tWindowId
local tBrowserId
put revBrowserOpen(tWindowId, pUrl) into tBrowserId
if tBrowserID contains "error" or tBrowserId is not an integer then
answer warning tBrowserId
exit to top
end if
set the altBrowserID of this stack to tBrowserId
end abOpenBrowser
on abIamBusy
set the repeatcount of img "busy.gif" to -1
put "Accessing page:" && the altCurrURL of this stack into fld "logfield" of this stack
end abIamBusy
on abIamNotBusy
set the repeatcount of img "busy.gif" to 0
set the currentframe of img "busy.gif" to 1
put "Finished" into fld "logfield" of this stack
end abIamNotBusy
on browserClosing pId
end browserClosing
on browserNewUrlWindow pId, pUrl
answer "link trying to open in new window:"&cr&pURL
revBrowserSet pId, "url", pUrl
end browserNewUrlWindow
on browserNavigateComplete pId, pUrl
end browserNavigateComplete
on browserBeforeNavigate pId, pUrl
abIamBusy
global browserCancel
if pURL contains "xxx.com" then
abIamNotBusy
answer warning "Won't allow you to go to domain xxx.com! See XBrowser_BeforeNavigate!"
put true into browserCancel
end if
end browserBeforeNavigate
on browserNavigateCompleteFrame pId, pUrl
end browserNavigateCompleteFrame
on browserBeforeNavigateFrame pId, pUrl
abIamBusy
end browserBeforeNavigateFrame
on browserDocumentComplete pId, pUrl
abIamNotBusy
put pURL into fld "FileAddress" of this stack
local tUrl
put fld "FileAddress" into tUrl
set the altCurrURL of this stack to tUrl
end browserDocumentComplete
on browserDocumentCompleteFrame pId, pUrl
abIamNotBusy
put pURL into fld "FileAddress" of this stack
local tUrl
put fld "FileAddress" of this stack into tUrl
set the altCurrURL of this stack to tUrl
end browserDocumentCompleteFrame
on browserDownloadRequest pId, pUrl
answer information "The browser is attempting to download the file: " & return & pURL & return & return & "Please handle this in the 'DownloadRequest' callback'"
abIamNotBusy
#revBrowserStop the altBrowserId of this stack
end browserDownloadRequest
Re: Calling local html files in revBrowser using a relative path
Hi mebtrek,
well I meant the current "Browser example" of LiveCode, but I had a quick look at it,
and it actually still uses this old syntax from the externals ancestor "altBrowserExternal"!?
Your script looks OK and if it works for you, why change it?
Best
Klaus
well I meant the current "Browser example" of LiveCode, but I had a quick look at it,
and it actually still uses this old syntax from the externals ancestor "altBrowserExternal"!?

Your script looks OK and if it works for you, why change it?

Best
Klaus
Re: Calling local html files in revBrowser using a relative path
As a final follow-up to this post, I wish to clarify the intent and use of use of a simplified revBrowser for displaying local html files and to submit simplified code for us in that intent. I want to embed complex spreadsheets made from Excel and converted to calculating Html files via ExcelEverywhere into LiveCode aps so they can run independent of an external browser, such as Explorer, Firefox, etc. in a LiveCode app instead. Thus, the browser need only be very simple and it can bypass the address window, nav buttons and other revBrowser coding objects. For example, following is a pic of a simple revBrowser screen having only a single generic LiveCode button to return to the main menu. In it is a simple local html file running in a revBrowser window. I've found that far more complex html files, including made sites on the local computer run fine from their own html code, buttons and pages all running within this simple revBrowser. Complex spreadsheets converted to calculating html pages are far, far easier to develop in Excel than using LiveCode Data grid components, that really do not begin to compare. Alternatively, however, they can be used but with an extraordinary extent and level of coding. The one advantage, though, would be that no external html files would need to be distributed as part of the application. Presumably there will be ongoing development of LiveCode spreadsheeting / datagrid components.
[img][T:\Temp_Downloads/Brwser Window.png]
START OF CODE FOR MINIMAL revBROWSER ===============================================
Following is the only minimum code needed for the above revBrowser:
on openstack
put the effective filename of this stack into tFile
set itemdel to "/"
put "Called Files/HTML-01.html" into item -1 of tFile
put "file://" before tFile
set the altHomeURL of this stack to tFile
send "initAltBrowser" to this card in 1 second
end openstack
on initAltBrowser
abOpenBrowser the altHomeURL of this stack
revBrowserSet the altBrowserId of this stack, "showborder", true
revBrowserSet the altBrowserId of this stack, "rect", the rect of image "BrowserArea"
revBrowserRedraw the altBrowserId of this stack
end initAltBrowser
on abOpenBrowser pURL
local tWindowId
put the windowid of this stack into tWindowId
local tBrowserId
put revBrowserOpen(tWindowId, pUrl) into tBrowserId
if tBrowserID contains "error" or tBrowserId is not an integer then
answer warning tBrowserId
exit to top
end if
set the altBrowserID of this stack to tBrowserId
end abOpenBrowser
END OF CODE FOR MINIMAL revBROWSER ===============================================
[img][T:\Temp_Downloads/Brwser Window.png]
START OF CODE FOR MINIMAL revBROWSER ===============================================
Following is the only minimum code needed for the above revBrowser:
on openstack
put the effective filename of this stack into tFile
set itemdel to "/"
put "Called Files/HTML-01.html" into item -1 of tFile
put "file://" before tFile
set the altHomeURL of this stack to tFile
send "initAltBrowser" to this card in 1 second
end openstack
on initAltBrowser
abOpenBrowser the altHomeURL of this stack
revBrowserSet the altBrowserId of this stack, "showborder", true
revBrowserSet the altBrowserId of this stack, "rect", the rect of image "BrowserArea"
revBrowserRedraw the altBrowserId of this stack
end initAltBrowser
on abOpenBrowser pURL
local tWindowId
put the windowid of this stack into tWindowId
local tBrowserId
put revBrowserOpen(tWindowId, pUrl) into tBrowserId
if tBrowserID contains "error" or tBrowserId is not an integer then
answer warning tBrowserId
exit to top
end if
set the altBrowserID of this stack to tBrowserId
end abOpenBrowser
END OF CODE FOR MINIMAL revBROWSER ===============================================