Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-2578] iOS: WebView event beforeLoad.url property

GitHub Issuen/a
Resolution Date2012-03-05T10:50:35.000+0000
Affected Version/sRelease 1.5.0
Fix Version/sn/a
ReporterJérémy R
AssigneeNeeraj Gupta


When a user click on a link inside the WebView, the received event URL property isn't correctly setted.

webview.addEventListener('beforeload', function(e) {



source = "[object TiUIWebView]";
type = beforeload;
url = "file://localhost/Users/myuser/Workspace/TitaniumWorkspace/MyApp/Resources/procedureHTML/06_07_2010/11_00.html";

I have a local HTML file with different type of links (towards PDF, DOC, etc). I have to prevent some default behavior.

When also registering a "load" event, which is called just after, the url is correctly configured.

SDK 1.5.0 GA & 1.5.1 nightly


  1. hal 2011-04-15


    While this may be a valid bug, you have not have explained this ticket thoroughly-enough to be useful. Would you follow http://developer.appcelerator.com/guides/en/contribute.html#submitting_bugs"> this guide and fill in the missing information, please?


  2. Chris D 2011-04-15

    Please assign and increase priority of this ticket for iOS.

    Anyone developing web browsing apps is going to eventually need the ability to examine the URL before loading in the web view for URL filtering and information pop-ups, etc.

    Here's a Use Case:

    In iOS create a WebView with TouchScreen enabled and it loads the URL defined at WebView creation. User touches the screen on a hyperlink and WebView starts to load a malicious or advertising site. The app creator can provide in the app a whitelist of trusted URLS (or domains) to prevent loading of such websites and alert the user that the site has been blocked. To do this the url property of the WebView must be updated at the 'beforeload' event or there is no way to detect the pending page load.

    Per your workflow I've posted to the community Q&A for potential work arounds.

    Thanks, Chris

  3. Dave Court 2011-04-15

    In addition, there seems to be no way to prevent the webview from loading an URL, after inspecting it during the beforeload event.

    On iOS, you'd normally use shouldStartLoadWithRequest in the webview proxy to do this. But I see from the code that Appcelerator unconditionally returns YES on that method.

    To implement the sort of behaviour described in this ticket, I think it's necessary to provide some sort of bridge to that method - or to provide an additional API method to abort the current URL, usable within the beforeload event. Without that, some important functionality is crippled compared with native iOS apps.

    Note that I've tried issuing stopLoading() from within beforeload, but it doesn't work - presumably because the event is asynchronous and so can't get to the request in time.

    I presume there's an equivalent way of doing this on Android, but I haven't looked into it yet.

  4. corey 2011-04-15

    This would be a huge help. Being able to detect what URL the user is trying to load before it loads is a must for security and for app integration with webview.

    I for one would like to capture a URL from a share button in webview and preform facebook, twitter etc functions with in the app rather than going to the web version of said social site.

    Please fix the beforeload event to update the URL, also, being able to stop the URL from loading, like cancelLoad() or something would be great too.

    THanks, keep up the good work!

  5. corey 2011-04-15

    Please Fix This!

  6. netpro2k 2011-04-15

    I agree, getting before-load to work, or better yet a wrapper around shouldStartLoadWithRequest would be extremely helpful. Our current workaround is to use load and then reload the previous url immediately after performing the required actions, but this is less than ideal for many reasons.

  7. Jim C. 2011-04-15

    Is there a fix/feature planned? Apologize if I missed a roadmap document somewhere.

    I am developing an eCommerce application. I would like to do the following on iOS and Android. Currently testing on iOS.

    • receive page load event (beforeload works)
    • interrogate the URL (e.url or object.url does not work)
    • cancel the page load (stopLoading works)
    • display an alert (createAlertDialog)
    • goback to previous page (goBack... not sure if page reload is necessary)
           logger('webview1 beforeload event : webview1.url = ', webview1.url);
           // Broken.  
           logger('webview1 beforeload event : e.url = ', e.url );     
           logger('webview1 stopLoading call', '');
           Titanium.UI.createAlertDialog({title:'Alert', message:'Browsing Canceled.'}).show();
           logger('webview1 goBack call', '');     


  8. Diego 2011-04-15

    I am building a safe browser app for the iPhone and it requires validating the url before it is loaded. Seems 'beforeload' event and being able to call webView.stopLading() if the url is not allowed is fundamental in this case.

    Any idea on when this problems will be fixed?

    Keep up the great work!

  9. Stephen Tramer 2011-04-15

    Still not enough information in the ticket to be able to handle it.

  10. Dave Court 2011-04-15

    I found this article, which contains a neat trick that will maybe help in cases where you're in control of the HTML and able to convert elements appropriately:

    http://boydlee.com/appcelerator-titanium/capturing-titanium-events-from-webview-to-app-code.html"> http://boydlee.com/appcelerator-titanium/capturing-titanium-events-...

    It's certainly what I'll be trying to work around this problem.

  11. Yaniv Nagar 2011-05-12

    Let me elaborate on the problem: whenever using the "beforeLoad" event, the e.url returns the original url the webView was opened from, and not the url that the webView is going to load next. I've tried to look at TiUIWebView.m, and changed: NSDictionary *event = url == nil ? nil : [NSDictionary dictionaryWithObject:[url absoluteString] forKey:@"url"]; to: NSURL *currentURL = webView.request.URL; NSDictionary *event = url == nil ? nil : [NSDictionary dictionaryWithObject:[currentURL absoluteString] forKey:@"url"]; which gave better results, the link is now updated, but I always get the last link I was in, and not the next one. If I'm at page A and clicking to move to page B, I'll get A as the "currentURL".
  12. Yaniv Nagar 2011-05-12

    At last! I created a fix for it :) I should have used the "shouldStartLoadWithRequest" method instead of the "didStartLoad" one! go to /Library/Application Support/Titanium/mobilesdk/osx/1.6.2 (or 1.7)/iphone/Classes and edit TiUIWebView.m in the "shouldStartLoadWithRequest" method, look for: if ([scheme hasPrefix:@"http"] || [scheme hasPrefix:@"app"] || [scheme hasPrefix:@"file"] || [scheme hasPrefix:@"ftp"]) { return YES; } and replace with: if ([scheme hasPrefix:@"http"] || [scheme hasPrefix:@"app"] || [scheme hasPrefix:@"file"] || [scheme hasPrefix:@"ftp"]) { NSString *urlExtension = newUrl.absoluteString; NSArray *urlChunks = [urlExtension componentsSeparatedByString: @"."]; urlExtension = [urlChunks lastObject]; if ([urlExtension isEqualToString:@"zip"] || [urlExtension isEqualToString:@"pdf"] || [urlExtension isEqualToString:@"doc"]) { if ([self.proxy _hasListeners:@"fileDownload"]) { NSDictionary *event = newUrl == nil ? nil : [NSDictionary dictionaryWithObject:[newUrl absoluteString] forKey:@"url"]; [self.proxy fireEvent:@"fileDownload" withObject:event]; } return NO; } return YES; } save it and clean the project in the titanium IDE (Project/Clean), and build again. Now, for every url with the extension of ipa or zip (you can add more, look at the code), you'll get the "fileDownload" event in Titanium :) I hope appcelerator will add this fix in the next sdk version :)
  13. connysvensson 2011-09-29

    Ok, so everyone has agreed this is a bug and we have a solution for it. People are screaming for a fix (check Q&A). Why isn't this fixed yet? It's stopping us from building the apps we want. I have patched the code myself as described above but that shouldn't be necessary.
  14. Don Thorp 2011-10-06

    We cannot accept code submitted in JIRA tickets. If the original author Yaniv Nagar wants to submit a pull request for it and sign the CLA then we can look at the code.
  15. connysvensson 2012-03-06

    What is the duplicate JIRA ticket, so I can follow that?
  16. Neeraj Gupta 2012-03-06

  17. Lee Morris 2017-03-22

    Closing ticket as duplicate of the ticket that is mentioned above.

JSON Source