As I had reviewed the document it seems to me the same code I have used which mentioned there.
It seems you want to trigger some behavior when clicking on some internal page element.
On web platforms, you can’t use scheme method, as mentioned in the doc,
Due to limitations of the Web platform, it can not be implemented by this mechanism, but internal pages can interact in the following ways:
<html>
<body>
<dev>
<input type="button" value="Trigger" onclick="onClick()"/>
</dev>
</body>
<script>
function onClick () {
// If TestCode is defined on window, then
parent.TestCode();
}
</script>
</html>
So you can write a callback to call parent functions in side. Remember the parent
refer to window
in your Cocos game page.
By the way, you also need to make sure the callback is attached to the click callback of the target element you want to trigger.
@pandamicro I don’t have any doubt for the web platform, On the web it’s working fine, but on the Android/iOS build it’s not working, and the html code which is loading in the webview is mentioned below,
<body style="background-color:'white';">
<center>
<div>
<input id="trigger-button" type="button" value="Trigger" onclick="onClick()"/>
</div>
<div>
<a href="https://example.com"><img src="https://bulma.io/images/placeholders/480x800.png" alt="Poster Image"></a>
</div>
</center>
<div id="close-button" onclick="javascript:window.parent.postMessage({type: 'close'}, '*');">Close</div>
</body>
<script>
function onClick () {
// One of them sets up the URL scheme
document.location = 'testkey://a=1&b=2';
}
</script>
I have taken look at your script, but it seems you haven’t setup scheme callback for native platform, you need to do some extra work in AppylarScriptV2
These are critical to let your component receive callbacks when the internal web page set document.location
with corresponding scheme (testkey in the current case)
let scheme = "testkey";
function jsCallback (target, url) {
// The return value here is the URL value of the internal page, and it needs to parse the data it needs.
let str = url.replace(scheme + '://', ''); // str === 'a=1&b=2'
// webview target
console.log(target);
}
interstitialWebView.setJavascriptInterfaceScheme(scheme);
interstitialWebView.setOnJSCallback(jsCallback);
From your code, the webview component is only added in AppylarScriptV2.showInterstitial
, which is not executed in constructor, are you sure your setup of webview is successful
Yes, It’s working,
https://drive.google.com/file/d/10v81vcEL2bZyHVKxF29w8YgomZ5DhWKw/view?usp=sharing
As shown in the video attached.
have you checked the video shared, any update?