鸿蒙Next 不支持plus之后,类似于plus.runtime.openUrl这种在外部浏览器打开H5地址的功能

a***@mori-building.com
- 发布:2025-01-21 14:04
- 更新:2025-01-21 16:29
- 阅读:276

提供一下一个示例,这个示例放到 uts 插件中即可使用,大部分代码如此所示:
openURL(url : string, errorCB ?: (result : any) => void, identity ?: string) {
let context = getContext() as common.UIAbilityContext;
let link : string = url;
let openLinkOptions : OpenLinkOptions = {
appLinkingOnly: false,
};
context.openLink(link, openLinkOptions, (result) => {
if (errorCB) {
errorCB(result); // 只有在 errorCB 存在时才调用
}
}).then(() => {
console.info(`open link success.`);
}).catch((err : BusinessError) => {
console.error(`open link failed, errCode ${JSON.stringify(err.code)}`);
});
}
淡e痕
粘过去报错了,getContext()不能这么获取,用新文档里的_window.getUIContext().getHostContext();又没有openLink,无解,怎么搞
2025-09-25 19:03
DCloud_UNI_yuhe
回复 淡e痕: 不应该啊,有报错信息吗?
2025-10-13 19:10