////////////////////////////////////
cc.Class({
extends: cc.Component,
properties: {
webViewNode: {
default: null,
type: cc.Node,
},
webView: {
default: null,
type: cc.WebView,
}
},
// LIFE-CYCLE CALLBACKS:
onLoad() {
cc.find("Canvas/size").getComponent(cc.Label).string = cc.view.getVisibleSizeInPixel();
cc.find("Canvas/RootNode/LeftNode").getComponent(cc.Label);
this.initWebViewSize();
//this.webView.url = 'https://m.baidu.com';
var ss = "555555";
//this.webView.evaluateJS('onClick1('+ss+')');
},
start() {
},
btnAction: function() {
Alert.show("难道还有这种操作?");
},
initWebViewSize: function() {
console.log("leftheight=" + cc.find("Canvas/RootNode/LeftNode").height);
console.log("leftwidth=" + cc.find("Canvas/RootNode/LeftNode").width);
var viewSize = cc.view.getVisibleSizeInPixel();
var viewWidth = (viewSize.width / viewSize.height) * 720 - 98;
var viewPaddingWidth = viewSize.width - 98;
console.log("viewSize=" + JSON.stringify(viewSize) + " ;viewWidth=" + viewWidth + ";viewPaddingWidth=" + viewPaddingWidth);
this.webViewNode.width = viewWidth;
console.log("this.webViewNode.x=" + this.webViewNode.x + ";this.webViewNode.y=" + this.webViewNode.y);
},
// update (dt) {},
onWebFinishLoad: function(sender, event) {
console.log("onWebFinishLoad == =" + sender);
var loadStatus = "";
if (event === cc.WebView.EventType.LOADED) {
var ss = "sss565454";
this.webView.evaluateJS('onClick1('+ss+')');
loadStatus = " is loaded!";
} else if (event === cc.WebView.EventType.LOADING) {
loadStatus = " is loading!";
} else if (event === cc.WebView.EventType.ERROR) {
loadStatus = ' load error!';
}
console.log("onWebFinishLoad=" + loadStatus);
},
});
///////////////////////////////////////////////////////////////
错误提示
eruda.min.js:2 DOMException: Blocked a frame with origin “http://localhost:7456” from accessing a cross-origin frame.
at TheClass.evaluateJS (http://localhost:7456/app/engine/bin/cocos2d-js-for-preview.js:41126:17)
at PWebView.evaluateJS (http://localhost:7456/app/engine/bin/cocos2d-js-for-preview.js:19196:38)
at MallHome.onWebFinishLoad (http://localhost:7456/preview-scripts/assets/scripts/mall/MallHome.js:62:26)
at cc_ClickEvent.emit (http://localhost:7456/app/engine/bin/cocos2d-js-for-preview.js:14891:17)
at Function.emitEvents (http://localhost:7456/app/engine/bin/cocos2d-js-for-preview.js:14876:19)
at PWebView._onWebViewLoaded (http://localhost:7456/app/engine/bin/cocos2d-js-for-preview.js:19177:35)
at TheClass._dispatchEvent (http://localhost:7456/app/engine/bin/cocos2d-js-for-preview.js:41144:30)