Open AND Close browser window overlay on card?? Possible???

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
sylvanr
Posts: 80
Joined: Wed Nov 24, 2010 10:38 am

Open AND Close browser window overlay on card?? Possible???

Post by sylvanr » Fri Jul 08, 2011 8:41 pm

In my app, I have some url links and currently when the user clicks on a link, my app closes and the link is opened in the Safari browser. When the user is done with the link in the Safari browser, they must close the Safari browser and then look for my app on their iPhone and re-open my app and then go back to the card where they left off. I am wondering if all that is necessary? Is it possible for them to stay on the card with the link and open a browser overlay rather than exiting out of my app and then have a close button on the browser overlay so that when they close the browser, they are still on the same card where they left off???

The reason that this occurred to me is that I had recently been trying to figure out how the user could take a pic while on a card and I was convinced that a script would have to take them out of my app to take the pic and then they would have to re-open my app, but with the great advise of users on this forum, I discovered my approach was all wrong and that it was possible to have a camera overlay pop up, take a pic and then close and still be on the same card within my stack. THAT is so much more elegant and user friendly! I am wondering if there is a way to do the same thing with urls?? Is it possible to click a button, open a window overlay, go to the url, and then click a button on the window overlay that closes that window and returns the user back to the card where they left off??? That would be exquisite!! :D

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Open AND Close browser window overlay on card?? Possible???

Post by Mark » Sat Jul 09, 2011 12:10 am

Use the native browser control.

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Jellicle
Posts: 453
Joined: Thu Feb 24, 2011 11:07 am

Re: Open AND Close browser window overlay on card?? Possible???

Post by Jellicle » Sat Jul 09, 2011 12:27 am

Mark wrote:Use the native browser control.

Mark
Check out the browser example stack that comes with LC. it's got most of the code you'll be needing. Or get MobGUI. It makes stuff like this trivial to implement.

Gerry
14" MacBook Pro
Former LiveCode developer.
Now recovering.

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Open AND Close browser window overlay on card?? Possible???

Post by Mark » Sat Jul 09, 2011 1:15 am

I'm not sure that the sample stack works on iOS...?

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Jellicle
Posts: 453
Joined: Thu Feb 24, 2011 11:07 am

Re: Open AND Close browser window overlay on card?? Possible???

Post by Jellicle » Sat Jul 09, 2011 1:59 am

Mark wrote:I'm not sure that the sample stack works on iOS...?

Mark
It's designed for iOS, so why wouldn't it? :) (I mean the file Browser Example.livecode, in the Mobile examples folder).
14" MacBook Pro
Former LiveCode developer.
Now recovering.

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Open AND Close browser window overlay on card?? Possible???

Post by Mark » Sat Jul 09, 2011 9:24 am

ok, I looked for it and indeed there is a sample stack that works on iOS.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

sylvanr
Posts: 80
Joined: Wed Nov 24, 2010 10:38 am

Re: Open AND Close browser window overlay on card?? Possible???

Post by sylvanr » Sat Jul 09, 2011 10:50 am

OK. I couldn't figure out how to have an overlay popping up over a card, so instead I took the card from the browser stack that came with LC and with minimal alterations, integrated it into my stack on a card called "browser." Then when I have a url that I want the user to be able to open, they click on a button which I will call "URL Button" for now, which has the following script:

on mouseUp
mark this card
go to card "browser"
end mouseUp

On the browser card, I have a button called "DONE" with the following script to bring them back to the card where they left off when they are done looking at the url I have sent them to:

on mouseUp
go to next marked card
end mouseUp

Then I used the script that had come with the example on the card itself and it opens Google fine but I am having trouble figuring out how to have it open the link I want it to open rather than the Google. In the following script, there is a line to "set up a suitable initial url:"

iphoneControlSet sBrowserId, "url", "http://www.google.com"

Of course I can change the "http://www.google.com" to whatever I want in the browser card but I would like to be able to change it from the URL Button as there are several different url's in the stack and I only want one browser card. The url would be in the button with the script:

on mouseUp
mark this card
go to card "browser"
open url "http://www.whatever.com" (or something like that???)
end mouseUp

BUT that doesn't seem to work?

The card script from the browser card:

-- We use this variable to store the id of the UIWebView native
-- control.
local sBrowserId

on preOpenCard
if the environment is not "mobile" then
exit preOpenCard
end if

-- Create our browser control and store the id
iphoneControlCreate "browser"
put the result into sBrowserId

-- Native controls start off invisible
iphoneControlSet sBrowserId, "visible", "true"

-- Set up a suitable initial url
iphoneControlSet sBrowserId, "url", "http://www.google.com"

-- Make sure everything is the right size
resizeStack
end preOpenCard

on closeCard
if the environment is not "mobile" then
exit closeCard
end if

-- Destroy the control, if we fail to do this native UIViews
-- will just accumulate
iphoneControlDelete sBrowserId
end closeCard

on resizeStack
if the environment is not "mobile" then
exit resizeStack
end if

-- Adjust the size of the URL entry field
set the rect of field "URL" to the left of field "URL", the top of field "URL", the width of this card - 4, the bottom of field "URL"

-- Adjust the size of the browser view
set the rect of group "Browser" to the left of group "Browser", the top of group "Browser", the width of this card - 4, the height of this card - 10

-- Adjust the status field
set the rect of field "Status" to 4, the bottom of group "Browser" + 4, the width of this card - 4, the height of this card - 4

-- Now adjust the control itself
iphoneControlSet sBrowserId, "rect", the rect of group "Browser"
end resizeStack

--------

-- This message is received after a request has been allowed and
-- loading is starting
on browserStartedLoading pUrl
put "Started loading:" && pUrl into field "Status"
end browserStartedLoading

-- This message is received when a page has been completely
-- loaded and is displayed to the user
on browserFinishedLoading pUrl
put "Finished loading:" && pUrl into field "Status"
put pUrl into field "Url"
end browserFinishedLoading

-- This message is received when a new url is requested. Passing it
-- causes the load to go ahead, otherwise it does not.
on browserLoadRequest pUrl, pReason
answer "Do you want to load:" && pUrl with "Yes" and "No"
if it is "Yes" then
pass browserLoadRequest
else
put "Refused:" && pUrl into field "Status"
end if
end browserLoadRequest

--------

-- This handler is invoked by our Back/Forward/Stop/Refresh buttons
-- we just pass the request onto the control.
command doAction pAction
if the environment is not "mobile" then
exit doAction
end if

iphoneControlDo sBrowserId, pAction
end doAction

-- This handler is invoked when the url field is closed after editing.
-- It causes a new url to be requested
command goUrl pUrl
if the environment is not "mobile" then
exit goUrl
end if

iphoneControlSet sBrowserId, "url", pUrl
end goUrl

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Open AND Close browser window overlay on card?? Possible???

Post by Mark » Sat Jul 09, 2011 11:07 am

Hi,

It really puzzles me why you replace the iphoneControlSet command with the open url command if the example clearly tells you to use the iphoneControlSet command.

Use

Code: Select all

iphoneControlSet sBrowserId, "url", "http://www.google.com"
where sBrowserId is a global variable containing the ID of the browser instance, "url" defines the next parameter as a url string property and "http://www.google.com" is that url string. Now change the URL to whatever you want. You can execute this command as long as the browser instance exists. If it doesn't exist, create a new instance first.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

sylvanr
Posts: 80
Joined: Wed Nov 24, 2010 10:38 am

Re: Open AND Close browser window overlay on card?? Possible???

Post by sylvanr » Sat Jul 09, 2011 8:20 pm

Mark wrote:Hi,

It really puzzles me why you replace the iphoneControlSet command with the open url command if the example clearly tells you to use the iphoneControlSet command.

Use

Code: Select all

iphoneControlSet sBrowserId, "url", "http://www.google.com"
where sBrowserId is a global variable containing the ID of the browser instance, "url" defines the next parameter as a url string property and "http://www.google.com" is that url string. Now change the URL to whatever you want. You can execute this command as long as the browser instance exists. If it doesn't exist, create a new instance first.

Kind regards,

Mark
I am not "replacing the iphoneControlSet command with the open url command" in the card script. I only use the open url in the button script to illustrate what I am trying to do, although it does not work. The card script that came with the stack included with LC works perfectly as it is, and yes, I can change the url in that script to anything but that was not the point I was trying to make. I have several url buttons in my stack on different cards, going to different url's. I could have a separate browser card for each time I use a url button and use the original browser card script that came with LC and just change the url on each separate browser card. That WILL work but then I will have a lot of browser cards added to my stack. I was thinking that there should be a way of only having ONE browser card and change the url with a BUTTON script that would take the user to the same browser card each time with whatever url I want to send them to. THAT is the problem I am having. Maybe the only solution is to have a separate browser card for every url I use in the stack, and I can do that, but my guess is that there is someone on this forum that knows a better way of doing it that doesn't require a lot of extra cards. If I have ten url's within my stack and each url has a separate button that takes you to that url, it seems like you should not have to have a separate browser for each url? It seems the ten buttons would all be the same, taking you to ONE browser, but somehow change the url from within the button. I can do it with 10 buttons taking the user to 10 different browser cards but are 10 different browser cards really necessary??? That is my question. Sorry I wasn't clearer before. I hope this is clear now?? :?

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Open AND Close browser window overlay on card?? Possible???

Post by Mark » Sat Jul 09, 2011 8:48 pm

Hi,

I meant: you use open URL instead of iphoneControlSet.

Btw open url is a HyperCard command. In LiveCode it is launch URL, which is wrong anyway.

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Jellicle
Posts: 453
Joined: Thu Feb 24, 2011 11:07 am

Re: Open AND Close browser window overlay on card?? Possible???

Post by Jellicle » Sun Jul 10, 2011 4:23 am

So to summarise, you don't use open/launch url commands to change the contents of a browser object - you use iphoneControlSet instead.

Now as I understand it, you want to change the url displayed in an exisiting browser control from a button. So, as Mark has explained, you use something like this: iphoneControlSet sBrowserId, "url", "http://whatever.com" ... in your button script. Just make sure that when you first create the control you put its unique id into a global (sBrowserId in this case) so it can be used from a button. Your script from the example stack already does that, but you'll need to declare the global in your button script.

But stepping back a bit, it's possible to make a browser that pops up over a card, changes its url in response to user actions, and which can be closed, all without leaving the card. Keep thinking about it...you'll get there :)

Gerry
14" MacBook Pro
Former LiveCode developer.
Now recovering.

sylvanr
Posts: 80
Joined: Wed Nov 24, 2010 10:38 am

Re: Open AND Close browser window overlay on card?? Possible???

Post by sylvanr » Sun Jul 10, 2011 8:43 pm

iphoneControlSet sBrowserId, "url", "http://whatever.com"
YAY!!!! It works!! It works!!! YAY!!! Sometimes it is just amazing when something works. I can't understand why anyone would prefer playing computer games or slot machines. This is so much more fun... you try something over and over again... and then it works! Better than some little angry birds knocking something over or little coins trickling out of a machine....

Thank you all again!

For now, I will probably use the "browser" card but Gerry, you have intrigued me... You CAN make a browser pop up over a card??? Hm... I will have to come back to this now... for the challenge of it I guess... Let me think about it for a while... maybe give me a hint... I think that in 4D there was something like "open window" or maybe it was "open dialog." I can't remember ever doing anything like that in Hypercard. Hm. I will have to come back to this and maybe look at more sample stacks for something like that. Maybe a "palette?" Maybe it would be something invisible or in the background on the card and then the button would make it visible or bring it to the front?? Hm.. :? I will have to come back to that since I am too busy turning cartwheels now because
iphoneControlSet sBrowserId, "url", "http://whatever.com"
worked. Thanks!!

hliljegren
Posts: 111
Joined: Sun Aug 23, 2009 7:48 am
Contact:

Re: Open AND Close browser window overlay on card?? Possible???

Post by hliljegren » Mon Jul 11, 2011 9:07 am

Just to let you know...
When using browsers in your app you will get 17+ rating for your app as you can surf to any page on the web and not all of them are 3+ To get a lower rating you will also need to intercept all clicked links in the browser and redirect further clicks to Safari, or make sure that your web pages doesn't link to any other site. If you don't care about the 17+ rating you don't have to do anything of course...

Set delayRequests for the browser to true and then intercept all calls by including the command browserLoadRequset

Code: Select all

iPhoneControlSet sBrowserID, "delayRequests", "true"

on browserLoadRequest pUrl, pType
  // Intercept calls and do what you want with them like 
  launch url pURL // Will open the URL in Safari instead...
end browserLoadRequest
___________________________________
MacBook Pro M1 MAX 64 Gb,
LiveCode 10.0.1rc3

sylvanr
Posts: 80
Joined: Wed Nov 24, 2010 10:38 am

Re: Open AND Close browser window overlay on card?? Possible???

Post by sylvanr » Mon Jul 11, 2011 8:16 pm

Interesting. Thanks, that is good to know. Is it possible to just not have a URL entry field in a browser? In the browser example that came with LC, I deleted the forward button, back button and stop button and replaced them with one "DONE" button that just takes them back to the card from where they left off. I tried deleting the URL entry field and that seemed to mess the whole thing up. I'm not sure why. I assumed it must be mandatory to have it? If there was a way to get rid of it, I would like to do that.

hliljegren
Posts: 111
Joined: Sun Aug 23, 2009 7:48 am
Contact:

Re: Open AND Close browser window overlay on card?? Possible???

Post by hliljegren » Mon Jul 11, 2011 10:26 pm

You don't need it! I've used the browser control for my own projects without it. The field is just there to make it possible to add an URL of you send that to the browser via code you should not need the URL field.
___________________________________
MacBook Pro M1 MAX 64 Gb,
LiveCode 10.0.1rc3

Post Reply