Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-27238

Android: Allow "onlink" property to be set for first time after creating WebView

    Details

      Description

      Summary:
      On Android, the WebView "onlink" callback property currently must be assigned upon creation in order for it to work. It cannot be set after creation. (However, the "onlink" property can be changed after assigned upon creation.)

      Note that iOS supports setting "onlink" for the 1st time after creation and our API docs do not document it as a creation-only property. We should do this for convenience and parity.
      https://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.WebView-property-onlink

      Test case:

      1. Build and run the below code on Android.
      2. Tap on the WebView's "Show Alert" link.
      3. Notice that a "Webpage not available" appears onscreen.
      4. Build and run on iOS.
      5. Tap on the WebView's "Show Alert" link.
      6. Notice that an alert dialog is displayed. (The "onlink" callback was invoked.)

      var htmlText =
      		'<!DOCTYPE html>\n' +
      		'<html>\n' +
      		'	<head>\n' +
      		'		<meta name="viewport" content="width=device-width, initial-scale=1.0">\n' +
      		'	</head>\n' +
      		'	<body>\n' +
      		'		<p>WebView "onlink" Test</p>\n' +
      		'		<br/>\n' +
      		'		<br/>\n' +
      		'		<a href="mylink://show/alert">Show Alert</a>\n' +
      		'	</body>\n' +
      		'</html>\n';
       
      function onLinkHandler(e) {
      	if (e.url === "mylink://show/alert") {
      		alert("'onlink' callback invoked.");
      		return false;
      	}
      	return true;
      }
       
      var window = Ti.UI.createWindow();
      var webView = Ti.UI.createWebView({
      	html: htmlText,
      //	onlink: onLinkHandler,  // <- Must be set upon creation to work.
      });
      webView.onlink = onLinkHandler;
      window.add(webView);
      window.open();
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                ybanev Yordan Banev
                Reporter:
                jquick Joshua Quick
                Reviewer:
                Gary Mathews
                Tester:
                Ebenezer Boateng
              • Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Backbone Issue Sync

                  • Backbone Issue Sync is enabled for your project, but we do not have any synchronization info for this issue.

                    Git Source Code