Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-9080] iOS: send navigationType when beforeload event is fired in iOS webview

GitHub Issuen/a
TypeNew Feature
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2012-05-11T10:38:50.000+0000
Affected Version/sRelease 2.1.0
Fix Version/sRelease 2.1.0, Sprint 2012-10 API
ComponentsiOS
Labelscommunity, core, module_webview, qe-testadded
ReporterTommy Leung
AssigneeMax Stepanov
Created2012-05-03T10:39:37.000+0000
Updated2013-11-25T08:51:46.000+0000

Description

Implement UIWebViewNavigationType such that the beforeload event will include this in its parameters http://developer.apple.com/library/ios/#documentation/uikit/reference/UIWebView_Class/Reference/Reference.html Test case:
var win1 = Titanium.UI.createWindow({  
    navBarHidden:false
});

var webview1 = Ti.UI.createWebView({
  url: 'http://www.gmail.com'
});

webview1.addEventListener('beforeload', function(e){
    var navigationType = e.navigationType;

    if(Ti.UI.iOS.WEBVIEW_NAVIGATIONTYPE_LINK_CLICKED == navigationType){
      Ti.API.info("WEBVIEW_NAVIGATIONTYPE_LINK_CLICKED");
    } else if (Ti.UI.iOS.WEBVIEW_NAVIGATIONTYPE_FORM_SUBMITTED == navigationType){
      Ti.API.info("WEBVIEW_NAVIGATIONTYPE_FORM_SUBMITTED");
    } else if (Ti.UI.iOS.WEBVIEW_NAVIGATIONTYPE_BACK_FORWARD == navigationType){
      Ti.API.info("WEBVIEW_NAVIGATIONTYPE_BACK_FORWARD");
    } else if (Ti.UI.iOS.WEBVIEW_NAVIGATIONTYPE_RELOAD == navigationType){
      Ti.API.info("WEBVIEW_NAVIGATIONTYPE_RELOAD");
    } else if (Ti.UI.iOS.WEBVIEW_NAVIGATIONTYPE_FORM_RESUBMITTED == navigationType){
      Ti.API.info("WEBVIEW_NAVIGATIONTYPE_FORM_RESUBMITTED");
    } else if (Ti.UI.iOS.WEBVIEW_NAVIGATIONTYPE_OTHER == navigationType){
      Ti.API.info("WEBVIEW_NAVIGATIONTYPE_OTHER");
    }
});

var bb2 = Titanium.UI.createButtonBar({
  labels:['Back', 'Reload', 'Forward'],
  bottom: 0
});
var flexSpace = Titanium.UI.createButton({
  systemButton:Titanium.UI.iPhone.SystemButton.FLEXIBLE_SPACE
});
bb2.addEventListener('click',function(ce){
  if (ce.index == 0) { webview1.goBack(); }
  else if (ce.index == 1) { webview1.reload(); }
  else { webview1.goForward(); }
});

win1.add(webview1);
win1.add(bb2);

win1.open();

Comments

  1. Tommy Leung 2012-05-03

    Pull request https://github.com/appcelerator/titanium_mobile/pull/1902
  2. Max Stepanov 2012-05-11

    PR merged https://github.com/appcelerator/titanium_mobile/pull/1902
  3. Michael Pettiford 2012-06-12

    Closing issue Tested with Ti Studio build 2.1.0.201206111802 Ti Mobile SDK 2.1.0.v20120612102301 hash refeef019 OSX Lion 10.7.3 iPhone 4S OS 5.1 Verified that the navigation type is sent to the before load event
  4. jithinpv 2013-11-25

    Anvil test case added. PR link: https://github.com/appcelerator/titanium_mobile/pull/5020

JSON Source