Can I cancel the url request with a newWebView?

Hello,

I can see what the url is with the event listener for the newWebView. But I was wondering if I can look at the url and if it is something I do not want for any reason cancel the request and keep the current page without it leaving ever?

Thanks,

Warren

Hi Warren,

You’ll have to test the behavior on various platforms, but I think you could read the URL (in the listener), do your own logic to determine if it’s “valid” or not (in your estimation, whatever logic you consider makes it so), then do either of the following depending on what is happening:

  1. If the URL is “invalid”, stop loading it:

https://docs.coronalabs.com/api/type/WebView/stop.html

  1. If the URL loads, and you get a “loaded” event from the “urlRequest” event, use the “back” function to return to the previous page:

https://docs.coronalabs.com/api/event/urlRequest/type.html

https://docs.coronalabs.com/api/type/WebView/back.html

Hope this helps,

Brent

Hi Warren,

You’ll have to test the behavior on various platforms, but I think you could read the URL (in the listener), do your own logic to determine if it’s “valid” or not (in your estimation, whatever logic you consider makes it so), then do either of the following depending on what is happening:

  1. If the URL is “invalid”, stop loading it:

https://docs.coronalabs.com/api/type/WebView/stop.html

  1. If the URL loads, and you get a “loaded” event from the “urlRequest” event, use the “back” function to return to the previous page:

https://docs.coronalabs.com/api/event/urlRequest/type.html

https://docs.coronalabs.com/api/type/WebView/back.html

Hope this helps,

Brent