腾讯地图在h5下面 uni.getLocation uni.chooseLocation失败,经过几天发现是Referer为空;系欸版办法如下,请官方级市修复。
解决代码如下:
onLoad: function() {
// ===== H5 端:强制所有 script 标签发送 Referer(修复 uni.chooseLocation 空白)=====
// #ifdef H5
if (!window.scriptReferrerFixed) {
window.scriptReferrerFixed = true;
var originalCreateElement = document.createElement;
document.createElement = function(tagName) {
var el = originalCreateElement.call(document, tagName);
if (tagName.toLowerCase() === 'script') {
el.referrerPolicy = 'origin';
}
return el;
};
}
// #endif
uni.showLoading({ title: '加载中...' });
// ... 你原来的 onLoad 代码 ...
}
0 个回复