Not returned callback also press the button on the webview.
Because I don’t know, please tell me the simple example ?
test.html
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="format-detection" content="telephone=no">
<meta name="robots" content="none" />
</head>
<body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="js/sp.js"></script>
<ul class="slideshow">
<li>
<a href="#" onclick='sp.call("test1")'>
<img src="img/test1.jpg" width="100%"/>
</li>
</ul>
<style>
.bx-default-pager {
display: none;
}
.bx-viewport {
border: none !important;
}
</style>
</body>
</html>
sp.js
(function(){
var sp = {};
var isAndroid = navigator.userAgent.match(/Android/);
var isIOs = navigator.userAgent.match(/iPhone/) || navigator.userAgent.match(/iPod/) || navigator.userAgent.match(/iPad/);
sp.call = function(text){
if(isAndroid){
window.Cocos2dx.call(text);
} else if (isIOs) {
window.location.href = "cocos2dx:" + text;
} else {
window.location.href = text;
}
};
window.sp = sp;
})();
HelloWorld.cpp
bool HelloWorld::init()
{
auto webView = cocos2d::experimental::ui::WebView::create();
webView->loadURL("https://test.html);
webView->setOnJSCallback(CC_CALLBACK_1(HelloWorld::callbackFromJS,this));
webView->setAnchorPoint(Point(0,0));
webView->setPosition(Point(0,150));
webView->setContentSize(Size(WINSIZE.width,WINSIZE.height-150));
this->addChild(webView);
}
void HelloWorld::callbackFromJS(cocos2d::experimental::ui::WebView* webview, std::string* &msg)
{
CCLOG("callbackFromJS");
}