title | description |
---|---|
WKUserScript |
Plugin to add WKUserScripts in WKWebView (iOS). |
Plugin to add WKUserScripts in WKWebView (iOS). This can be used to inject JS code to all iframes of your app, for example to intercept window.open calls.
Please notice that this plugin requires you to use WKWebView.
This plugin isn't published in npm yet, so it must be installed via repo url:
cordova plugin add https://github.com/moodlemobile/cordova-plugin-wkuserscript
This plugin defines global WKUserScript
object.
Although in the global scope, it is not available until after the deviceready
event.
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
console.log(WKUserScript);
}
- WKUserScript.addScript
Adds a user script that will be injected to all iframes of the app (and also to the WebView, be careful with that). You can either pass the JS code to inject or the path of a JS script to inject.
- iOS 11+
WKUserScript.addScript({
code: 'window.myGlobalVar = "Test";',
}).then(function() {
// Success.
}).catch(function() {
// Error.
});