Page 1 of 1
HTML into an image object
Posted: Fri Jul 01, 2011 4:40 pm
by townsend
How do I get HTML from a Field variable into an Image object?
This code works well on displaying HTML from a local file:
Code: Select all
put "file:///z:\4livecode\test.html" into field my.url
put the windowid of this stack into tWinID
put revBrowserOpen(tWinID,field my.url) into sBrowserId
revBrowserSet sBrowserId, "rect",rect of image browser.image
Do I have to write my Field text to a file before it can be displayed?
Re: HTML into an image object
Posted: Fri Jul 01, 2011 6:55 pm
by Mark
Hi,
Your scripting style is horrible. You really need to fix that to make it easier for other people to read your scripts and help you.
I don't think you need a field. When you open a new browser window, you need to specify a URL. You don't need to put this URL into a field first. Nonetheless, your script should work. Do you see any errors or unexpected behaviour? What does sBrowserID contain? What is the result after executing the revBrowserSet command? Try this:
Code: Select all
put "file:///z:\4livecode\test.html" into myUrl
put the windowID of this stack into myWindowID
put revBrowserOpen(myWindowID,myUrl) into gBrowserID
if gBrowserID is an integer then
revBrowserSet gBrowserID,"rect",the rect of img "Name of Image"
put the result into rslt
if rslt is not empty then
beep
answer error rslt
end if
else
beep
answer error gBrowserID
end if
Always put quotes around object names, unless these object names are in variables. Instead of an image, you could use any placeholder, e.g. a transparent or even invisible button, or you could define a variable or constant in the script and assign a rect to it.
Kind regards,
Mark
Re: HTML into an image object
Posted: Fri Jul 01, 2011 7:26 pm
by townsend
That was just some code I copied from an example. I really didn't understand it completely-- but it worked.
I like your version much better. Okay... I'll start using quotes around my object names.
And... I probably didn't phrase my question correctly. What I was really trying to do is this.
When you put real HTML in the URL value, it doesn't work.
Code: Select all
put "<html><body>Hello World</body></html>" into myUrl --<<<====
put the windowID of this stack into myWindowID
put revBrowserOpen(myWindowID,myUrl) into gBrowserID
if gBrowserID is an integer then
revBrowserSet gBrowserID,"rect",the rect of img "browser.image"
put the result into rslt
if rslt is not empty then
beep
answer error rslt
end if
else
beep
answer error gBrowserID
end if
Thanks for your help Mark.
Re: HTML into an image object
Posted: Sat Jul 02, 2011 2:54 am
by Mark
Hi,
You might want to open a browser with an empty url. Unfortunately, this seems to be buggy and using about:blank might be more reliable. Replace
Code: Select all
put revBrowserOpen(myWindowID,myUrl) into gBrowserID
with
Code: Select all
put revBrowserOpen(myWindowID,"about:blank") into gBrowserID
Now put the htmlText into a variable and set the htmlText property of the browser window.
Code: Select all
put "<html><body>Hello World</body></html>" into myHtml
revBrowserSet gBrowserID,"htmlText",myHtml
Make sure to add the error checking procedures.
Kind regards,
Mark
Re: HTML into an image object
Posted: Sat Jul 02, 2011 7:13 pm
by townsend
Wow! That worked. Thanks Mark!
And just in case others are following along, here's the code:
Code: Select all
on mouseUp
put "<html><body>Hello World</body></html>" into myHTML
put the windowID of this stack into myWindowID
put revBrowserOpen(myWindowID, "about:blank") into gBrowserID
if gBrowserID is an integer then
revBrowserSet gBrowserID,"htmlText", myHtml
put the result into rslt
if rslt is not empty then
beep
answer error rslt
end if
revBrowserSet gBrowserID,"rect", the rect of image "browserimage"
put the result into rslt
if rslt is not empty then
beep
answer error rslt
end if
else
beep
answer error gBrowserID
end if
end mouseUp
An interesting point to note, to accomplish this, the revBrowserSet command had to be called twice with different parameters.