Last active
September 17, 2019 11:58
-
-
Save typeoneerror/5097118 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cordova> | |
<!-- ... --> | |
<plugins> | |
<!-- ... --> | |
<plugin name="OpenUrl" value="OpenUrl" /> | |
</plugins> | |
<!-- ... --> | |
</cordova> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript" src="cordova-2.3.0.js"></script> | |
<script type="text/javascript" src="js/jquery.js"></script> | |
<script type="text/javascript"> | |
document.addEventListener("deviceready", function() { | |
$(document).on('click', 'a._blank', function(event) { | |
event.preventDefault(); | |
var url = $(this).attr('href'); | |
var success = function(url) { | |
console.log('success! ' + url); | |
} | |
var error = function() { | |
console.log('error'); | |
} | |
// execute the plugin | |
// exec(successCallback, errorCallback, pluginName, pluginMethod, params) | |
cordova.exec(success, error, "OpenUrl", "openUrl", [url]); | |
// the other way that opens in the InAppBrowser (which sucks) | |
// window.open(url, '_blank'); | |
}); | |
}); | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/********* OpenUrl.h Cordova Plugin Header *******/ | |
#import <Cordova/CDV.h> | |
@interface OpenUrl : CDVPlugin | |
- (void)openUrl:(CDVInvokedUrlCommand*)command; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/********* OpenUrl.m Cordova Plugin Implementation *******/ | |
#import "OpenUrl.h" | |
#import <Cordova/CDV.h> | |
@implementation OpenUrl | |
- (void)openUrl:(CDVInvokedUrlCommand*)command | |
{ | |
CDVPluginResult* pluginResult = nil; | |
NSString *url = [command.arguments objectAtIndex:0]; | |
if (url != nil && [url length] > 0) { | |
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]]; | |
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:url]; | |
} else { | |
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR]; | |
} | |
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am getting this error, can you help me out?
Failed to restore plugin "OpenUrl" from config.xml. You might need to try adding it again. Error: Error: npm: Command failed with exit code 1 Error output: