email/web link

hi,

it’s a simple thing i have no doubt, but how do i create an email and web link??

thanks,

Rob [import]uid: 2131 topic_id: 342 reply_id: 300342[/import]

Hi Rob,

Check out the APIReference.pdf (from documentation tab). Look for system.openURL() - page 45.

This is how I did it in my test app:
local function openSafari(e)
if e.phase == “began” then
system.openURL(“http://www.google.com”)
end
end

linkButton = display.newImage(“mybutton.png”, 75, 445)
linkButton:addEventListener(“touch”, openSafari)

Same thing for email, just make url in format like mailto:nobody@mycompany.com

Cheers,
Mick

[import]uid: 4334 topic_id: 342 reply_id: 531[/import]

Cheers Mick,

I modified it a bit to make text link and it works a treat:

local function openSafari(e)
if e.phase == “began” then
system.openURL(“mailto:me@be.com”)
end
end

emaillink = display.newText(“email”, 125, 175, nil, 24 )
emaillink:setTextColor(255,255,255)
emaillink:addEventListener(“touch”, openSafari)

thanks again,

Rob [import]uid: 2131 topic_id: 342 reply_id: 537[/import]

Here’s one more way to do it, using the ui button class, just make sure you have ui.lua saved in the same folder as main.lua. This allows you to have the button or icon highlight when tapped:

local ui = require("ui")
local function openSafari(e)  
 system.openURL("http://www.google.com")  
end  
linkedImage = ui.newButton{ default="myImage.png", rollover="myImage\_over.png", onRelease=openSafari }

Here’s one more variation, which is helpful if you have more than one thing on the screen that is linked. Rather than figuring out which button was clicked, you can just attach a property containing the link and then access that property in the function.

local ui = require("ui")

local function gotoURL(e) local t = e.target system.openURL( t.link ) end

myButton1 = ui.newButton{ default="myImage.png", rollover="myImage\_over.png", onRelease=gotoURL } myButton1.link = "http://google.com"

myButton2 = ui.newButton{ default="myImage2.png", rollover="myImage2\_over.png", onRelease=gotoURL } myButton2.link = "http://bing.com" [import]uid: 3800 topic_id: 342 reply_id: 748[/import]

You can also add the cc, bcc, subject and body (make sure you escape them correctly)

eg

mailto:info@anscamobile.com?subject=Corona%20Rules&body=Congrats%20Ansca%20Mobile

Will fill the email field, to: info@anscamobile.com with the subject “Corona Rules” and body “Congrats Ansca Mobile”
Carlos

[import]uid: 24 topic_id: 342 reply_id: 751[/import]

what if you want to email an image from a corona app? [import]uid: 0 topic_id: 342 reply_id: 860[/import]

Hi all,

Is there any way to come back to main loop (I mean corona block execution) after a system.openURL call on complete. I.e. if there is a way to return to the lua code, once you have opened the iphone browser for instance. Some applications open iphone browser for something, but if you hit home button its return to caller program.

Is it possible on Corona programs?

Regards,

flavio [import]uid: 3022 topic_id: 342 reply_id: 879[/import]

correction:
system.openURL(“mailto:?subject=gamename%20is%20awesome&body=You%20should%20check%20this%20game%20out”)
does work [import]uid: 1560 topic_id: 342 reply_id: 9305[/import]

@flavio: not at the moment

@dotnaught : you need to put a mailto: subject. the mailto is empty.

mailto:info@anscamobile.xom?..

carlos [import]uid: 24 topic_id: 342 reply_id: 9307[/import]

If a link is clicked from inside a webOverlay does that force the user into Safari? [import]uid: 10248 topic_id: 342 reply_id: 9338[/import]

Unfortunately not Bark, so you either need to set up a webOverlay that doesn’t take up all the screen and add a button to close it, or not have any links within your weboverlay as otherwise users may get stuck there.

// red. [import]uid: 7143 topic_id: 342 reply_id: 9352[/import]

. [import]uid: 5712 topic_id: 342 reply_id: 9359[/import]

If you want to open Safari from a link in a Corona web popup, you can use the urlRequestListener handler to get the link URL and call system.openURL().

For example, say you a local HTML file bundled with your app that contains the following (abbreviated) HTML:

<!-- localpage.html -->  
  
[LINK](http://www.anscamobile.com)  
  

The following code loads the HTML file into a web pop-up, and defines a listener function that calls system.openURL() on the link the user tapped.

local function requestListener( event )  
 local shouldLoad = true  
  
 local url = event.url   
 system.openURL( url )  
  
 return shouldLoad  
end   
  
local options = { hasBackground=false, baseUrl=system.ResourceDirectory, urlRequest=requestListener }  
native.showWebPopup( "localpage.html", options )   

Tim [import]uid: 8196 topic_id: 342 reply_id: 9403[/import]