Detect Webview URL Change
I'm trying to sort out what event to attach to to detect when a webview's url (location) changes.
The sequence of events would be:
Open webview to http://domain-a.com
User completes form, gets redirected to http://my-totally-different-domain.com
Redirect triggers Titanium webview event which I capture.
2 Answers
-
The following code will fire whenever the url of the webview changes:
webView.addEventListener('load',function(){ Ti.API.debug('The URL changed to '+webView.url); });
And this code will fire whenever the webview redirects to the page you specify, if you put this code within the event listener:
var params = ""; var parts = (webView.url).replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) { params = params + m; }); url_base = (webView.url).replace(params,''); if (url_base == "http://www.example.com") { Ti.API.debug('we have arrived at the page you're waiting for'); }
For other methods of firing events from webviews, see this post.
-
Set height to webView
Thanks