wke响应网页js函数调用时注意:
必须等网页加载完成后,才能通过SetJsFunc设置js函数与c++回调的对应。网页未加载就设置,不会响应c++函数。
示例代码:
- wkeJSData* data = new wkeJSData();
- memset(data, 0, sizeof(wkeJSData));
- strcpy(data->typeName, (strfunc::I2A(i) + "_Function").c_str());
- data->callAsFunction = js_callAsFunction;
- data->finalize = js_releaseFunction;
- pWebCtrl->SetJsFunc("initFromClient", data);
- static wkeJSValue js_callAsFunction(wkeJSState* es, wkeJSValue object, wkeJSValue* args, int argCount)
- {
- wkeJSData *temp = wkeJSGetData(es, object);
- wchar_t text[1025] = { 0 };
- wchar_t title[1025] = { 0 };
- if (argCount >= 1)
- wcsncpy(text, wkeJSToTempStringW(es, wkeJSParam(es, 0)), 1024);
- if (argCount >= 2)
- wcsncpy(title, wkeJSToTempStringW(es, wkeJSParam(es, 1)), 1024);
- return wkeJSInt(es, 0);
- }
其中wkeJSData *temp = wkeJSGetData(es, object);获取到的data,
就是wkeJSData* data = new wkeJSData();
- static void js_releaseFunction(wkeJSData* data)
- {
- delete data;
- }
通过上面的函数,对new的数据删除