native.newWebView

@MagnoliaPower
thanks :slight_smile:
another situation
what if actually i didnā€™t know itā€™s itunes link or not.

what i have got is just a url link and this link just REDIRECT me to another URL

this url could just be a website or itunes link i canā€™t tell from original link.
a bit complicated.

Can i make it jump to itunes
or open in webview by two situations?
With same form url link?
for example:

abc.com?id=123 => redirect to website
abc.com?id=456 => redirect to itunes store
[import]uid: 25057 topic_id: 24291 reply_id: 117679[/import]

Does anyone knows if this is possible? To move the webview object by touch and drag? [import]uid: 106083 topic_id: 24291 reply_id: 117830[/import]

@OwenYang
Maybe you should download the content first with :

network.download( url, method, listener [, params], destFilename [, baseDir] )

or with somethinh like (just copy and paste one of my code, just for the idea, it will not work as is) :

 local http = require("socket.http")  
 local ltn12 = require("ltn12")  
  
--(...)  
local r, c, h = http.request{  
 method = "HEAD",  
 url = "http://myUrl/"..folder.."/"..fichier,  
 }  
  
 if c == 404 then  
 --print ("this "..fichier.." does not exist")  
 return false  
 end  
 if c == 200 then  
 myFile = io.open( dest\_folder.."/"..fichier, "w+b" )  
 local x,y = http.request{  
 url = "http://myURL/"..dossier.."/"..fichier,  
 sink = ltn12.sink.file( myFile ),  
 }  
 return true  
 end  
  

Then you can parse the file and decide what to do. [import]uid: 5578 topic_id: 24291 reply_id: 117838[/import]

@Johantd04, You can move content around within the webview (like any browser window) but you cannot add a ā€œtouchā€ listener to a webview. You can move the webview by changing itā€™s x and y properties so you could move it by touching another display object outside of the webview. [import]uid: 7559 topic_id: 24291 reply_id: 117889[/import]

I have tried this code

function listener( event )  
 local shouldLoad = true  
   
 local url = event.url  
 if 1 == string.find( url, "corona:close" ) then  
 -- Close the web popup  
 shouldLoad = false  
 end  
   
 if event.errorCode then  
 -- Error loading page  
 link.text = "Error: " .. tostring( event.errorMessage )  
 shouldLoad = false  
 end  
   
 return shouldLoad  
end  
  
-- Go Button Function  
function goButton:tap(e)  
 native.showWebPopup( 10, 10, 300, 300, "http://www.anscamobile.com", {urlRequest=listener} )  
  
 -- Back button visibility  
  
 bottomBar.isVisible = true  
 back.isVisible = true  
end  

Its from the sample. But the webview just flushes. Doesnā€™t stay for a long time. Its just like a blink [import]uid: 104777 topic_id: 24291 reply_id: 119577[/import]

I also have a problem with native.newWebView when it encounters a web page redirect. If the web page that I try to view is redirected with a 302 redirect, I get a blank screen instead of the web page I want to view.

I do not know how to test for this using newWebView. So I tried using the network.request with a listener. But I have not been able to solve problem. Network.request seems to return nil for status.

If I use network.setStatusListener, it takes several minutes to get a status. Sometimes I get timeouts. Sometimes I get 200 for a status instead of 302.

Would like to be able use newWebView to display web pages without using network and checking for events.

Is there a way to overcome the problem with the redirected pages. The redirected pages display in Safari.

[import]uid: 158629 topic_id: 24291 reply_id: 119639[/import]

I have tried this code

function listener( event )  
 local shouldLoad = true  
   
 local url = event.url  
 if 1 == string.find( url, "corona:close" ) then  
 -- Close the web popup  
 shouldLoad = false  
 end  
   
 if event.errorCode then  
 -- Error loading page  
 link.text = "Error: " .. tostring( event.errorMessage )  
 shouldLoad = false  
 end  
   
 return shouldLoad  
end  
  
-- Go Button Function  
function goButton:tap(e)  
 native.showWebPopup( 10, 10, 300, 300, "http://www.anscamobile.com", {urlRequest=listener} )  
  
 -- Back button visibility  
  
 bottomBar.isVisible = true  
 back.isVisible = true  
end  

Its from the sample. But the webview just flushes. Doesnā€™t stay for a long time. Its just like a blink [import]uid: 104777 topic_id: 24291 reply_id: 119577[/import]

I also have a problem with native.newWebView when it encounters a web page redirect. If the web page that I try to view is redirected with a 302 redirect, I get a blank screen instead of the web page I want to view.

I do not know how to test for this using newWebView. So I tried using the network.request with a listener. But I have not been able to solve problem. Network.request seems to return nil for status.

If I use network.setStatusListener, it takes several minutes to get a status. Sometimes I get timeouts. Sometimes I get 200 for a status instead of 302.

Would like to be able use newWebView to display web pages without using network and checking for events.

Is there a way to overcome the problem with the redirected pages. The redirected pages display in Safari.

[import]uid: 158629 topic_id: 24291 reply_id: 119639[/import]

Iā€™m at my witā€™s end here. Webview is working great for me with one very minor, yet very ANNOYING exception.

Iā€™m loading a webview with a remote HTML page. Iā€™m loading up a back button that is dependent on the ā€œcanGoBackā€ property. Unfortunately, the canGoBack option doesnā€™t fire every time so my back button isnā€™t always showing up when it is supposed to. Anyone else seen this?

Here is my code:

local webView = native.newWebView( 0, 100, 640, 589 )  
 webView:request( "http://www.MyRemoteWebPage.com/page1" )  
 local back = display.newImageRect( "btn-back.png", 160, 30 )  
 back.x = 90  
 back.y = 145  
 groupNews:insert( back )  
  
 local function webListener( event )  
 if webView.canGoBack == true then  
 back.isVisible = true  
 else  
 back.isVisible = false  
 end  
 end  
  
 local function backtap()  
 webView:back()  
 end  
  
 back:addEventListener("tap",backtap)  
 webView:addEventListener( "urlRequest", webListener )  

Iā€™ve been round and round this. Iā€™ve tried checking the URL string instead of using canGoBackā€¦same problem. What am I doing wrong? Anyone? Thanks.
[import]uid: 141982 topic_id: 24291 reply_id: 126633[/import]

The problem is the webView listener is called before the page is loaded so the canGoBack property isnā€™t valid yet. You need to poll it (with a timer) and check it when the page is loaded. I know this is a hack and the real solution is adding a listener that also fires when the page has finished loaded. Thatā€™s on our to-do list. [import]uid: 7559 topic_id: 24291 reply_id: 126647[/import]

Jumping in hereā€¦

You said, ā€œand check it when the page is loadedā€ but in the documentation I donā€™t see any way to find out whether the page has completed loading or not.

If thatā€™s the case then the only option I can see is to continuously poll to see if .canGoBack is available and if it ever changes to true then show the button. Can you think of another way?

Jay [import]uid: 9440 topic_id: 24291 reply_id: 126668[/import]

@jay, you are correct. Thatā€™s why I have put in a request for a ā€œdidLoadā€ listener so we know when to test the status. Waiting a second and polling for a bit is the only solution I know of.

Tom [import]uid: 7559 topic_id: 24291 reply_id: 126685[/import]

Iā€™m at my witā€™s end here. Webview is working great for me with one very minor, yet very ANNOYING exception.

Iā€™m loading a webview with a remote HTML page. Iā€™m loading up a back button that is dependent on the ā€œcanGoBackā€ property. Unfortunately, the canGoBack option doesnā€™t fire every time so my back button isnā€™t always showing up when it is supposed to. Anyone else seen this?

Here is my code:

local webView = native.newWebView( 0, 100, 640, 589 )  
 webView:request( "http://www.MyRemoteWebPage.com/page1" )  
 local back = display.newImageRect( "btn-back.png", 160, 30 )  
 back.x = 90  
 back.y = 145  
 groupNews:insert( back )  
  
 local function webListener( event )  
 if webView.canGoBack == true then  
 back.isVisible = true  
 else  
 back.isVisible = false  
 end  
 end  
  
 local function backtap()  
 webView:back()  
 end  
  
 back:addEventListener("tap",backtap)  
 webView:addEventListener( "urlRequest", webListener )  

Iā€™ve been round and round this. Iā€™ve tried checking the URL string instead of using canGoBackā€¦same problem. What am I doing wrong? Anyone? Thanks.
[import]uid: 141982 topic_id: 24291 reply_id: 126633[/import]

The problem is the webView listener is called before the page is loaded so the canGoBack property isnā€™t valid yet. You need to poll it (with a timer) and check it when the page is loaded. I know this is a hack and the real solution is adding a listener that also fires when the page has finished loaded. Thatā€™s on our to-do list. [import]uid: 7559 topic_id: 24291 reply_id: 126647[/import]

Jumping in hereā€¦

You said, ā€œand check it when the page is loadedā€ but in the documentation I donā€™t see any way to find out whether the page has completed loading or not.

If thatā€™s the case then the only option I can see is to continuously poll to see if .canGoBack is available and if it ever changes to true then show the button. Can you think of another way?

Jay [import]uid: 9440 topic_id: 24291 reply_id: 126668[/import]

@jay, you are correct. Thatā€™s why I have put in a request for a ā€œdidLoadā€ listener so we know when to test the status. Waiting a second and polling for a bit is the only solution I know of.

Tom [import]uid: 7559 topic_id: 24291 reply_id: 126685[/import]

I can confirm this exact same problem.The window does not appear at the x, y coordinates you specify in the call, at least for iPad. I see many people in this thread reporting the same thing. Has anyone found a workaround yet?

I wouldnā€™t mind a workaround if I could predict precisely where the window will be but so far I cannot see what the pattern is. One thing is certain. The combination of letterbox and iPad makes the window appear in unpredictable places. It works fine on iPhone.

[import]uid: 36466 topic_id: 24291 reply_id: 133507[/import]

We had a x,y positioning problem but it should be fixed in the Release build, 971. [import]uid: 7559 topic_id: 24291 reply_id: 133512[/import]

Thanks Tom. I tried 971, but just to help others that may find this thread, 971 release notes didnā€™t mention newWebView at all. Nevertheless I tried it and my code crashes on analytics. I see that 972 addresses analytics issues so hopefully that build will address both of these issues. [import]uid: 111723 topic_id: 24291 reply_id: 133535[/import]

The release build, 971 should not crash on analytics anymore. We fixed that in build 972 and ported the device templates so build 971 includes the fix.

The actual fix was not in build 971 but was included in the general release notes when we did a public release of 971:
OS: fixes casenum: 17123. If you call native.newWebViews(x,y,w,h) where x,y are not zero, then it would appear as if the webview were positioned at 2*x,2*y. This would cause touches to be clipped. This fixes both the positioning and touch clipping issues. [import]uid: 7559 topic_id: 24291 reply_id: 133539[/import]