You have to inject the code with a ScriptInjector, because the GWT-code may run within a hidden IFRAME (depends on the used Linker)
Inject external javascript code in JSNI
-
01-07-2022 - |
Question
I am integrating Google Wallet on my GWT app. At some point (at beginning of JSNI function purchase()
), I need to inject API JS code in my app.
<script src="https://sandbox.google.com/checkout/inapp/lib/buy.js"></script>
How can I do it?
public static native void purchase(String token) /*-{
// Success handler
var successHandler = function(status){
if ($wnd.console != undefined) {
console.log("Purchase completed successfully: ", status);
//window.location.reload();
}
}
// Failure handler
var failureHandler = function(status){
if ($wnd.console != undefined) {
console.log("Purchase failed ", status);
}
}
google.payments.inapp.buy({
'jwt' : token,
'success' : successHandler,
'failure' : failureHandler
});
}-*/;
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow