[英]How to access js window object in emscripten's EM_JS method?
Basically I want to access window.location in a EM_JS method to call this javascript method from c++.基本上我想在 EM_JS 方法中访问 window.location 以从 c++ 调用此 javascript 方法。
I tried like this我试过这样
EM_JS(const char*, getlocation, (), {
let location = window.location;
let length = lengthBytesUTF8(location) + 1;
let str = _malloc(length);
stringToUTF8(location, str, length);
return str;
});
But getting但是得到
ReferenceError: window is not defined
参考错误:window 未定义
Or is there any other way to get window.location in c++ code compiled with emscripten?或者有没有其他方法可以在用 emscripten 编译的 c++ 代码中获取 window.location ? But I don't want passing the value of window.location using js to c++ api using ccall or cwrap.
但我不想使用 js 将 window.location 的值传递给 c++ api 使用 ccall 或 cwrap。
The above code in the question just worked, just that I need to wait until the main is loaded to call this method, it seems.问题中的上述代码刚刚起作用,只是我似乎需要等到加载主程序才能调用此方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.