How to take the URL associated with the link?
Which API are you using?
If you are using this API: http://docs.coronalabs.com/api/library/native/showWebPopup.html
In your listener you can dump out all the values returned in the ‘event’ parameter like this:
for k,v in pairs(event) do print(k,v) end
native.newWebView( x, y, width, height , listener )
webView = native.newWebView( x, y, width, height , listener )
webView:request( “localFile.html”, system.DocumentsDirectory )
function listener (event)
If event.type == “link” then
function2(params)
end
end
I need the ‘url of the’ link to pass it as a parameter to the function2
thanks!!!
When event.type == “link”, you can use event.url to find out the url of the link that was activated.
- Andrew
Well, in the code above, you need to define the listener function before you call native.newWebView, or the ‘listener’ value you pass in the 5th parameter will be nil.
Ok thanks for your answers but I have one final question.
Event.url does not return the URL of the current page instead of the url of the link activated??
Yes that’s right.
- Andrew
ok but I need the ‘url of the’ link activated in the current page how can I do???
I’m not sure I understand what you mean. If you load “http://www.google.com”, then your listener will first receive an event with event.type == “loaded” and event.url == “http://www.google.com” when the page is finished loading. (Your listener will also receive a bunch of other events with event.type == “other” for various elements of the page as they load.) if that page contains a link, then when you click the link, your listener will receive an event with event.type == “link” and event.url == “[[url of the link that was clicked]]”.
- Andrew
Same way you’ve done it above, no?
Perfect now I think I understand. This is an example
function webListener (event)
if event.type == “loaded” then
print (“this is a current page”…event.url)
end
if event.type == “link” then
print ("this is the url of the link…event.url)
end
end
is it right?
Yes that’s right (except you’re missing a " mark in the second print statement). Note that you won’t actually receive the event.type == “link” event until the user actually clicks on the link.
- Andrew
I thank you for your availability.
Which API are you using?
If you are using this API: http://docs.coronalabs.com/api/library/native/showWebPopup.html
In your listener you can dump out all the values returned in the ‘event’ parameter like this:
for k,v in pairs(event) do print(k,v) end
native.newWebView( x, y, width, height , listener )
webView = native.newWebView( x, y, width, height , listener )
webView:request( “localFile.html”, system.DocumentsDirectory )
function listener (event)
If event.type == “link” then
function2(params)
end
end
I need the ‘url of the’ link to pass it as a parameter to the function2
thanks!!!
When event.type == “link”, you can use event.url to find out the url of the link that was activated.
- Andrew