前言:采用v-html方法處理
1.處理前
<html><head><meta http‐equiv="Content‐Type" content="text/html; charset=UTF-8"></head><body><form ?<input type="submit" value="立刻提交" style="display:none" >?</form>?<script>document.forms[0].submit();</script></body></html>
2.處理后
<form <input type="submit" value="立刻提交" style="display:none" >?</form>?<script>document.forms[0].submit();<\/script>
3.跳轉頁面方法
//傳參
uni.setStorageSync("ICBC_GW_V3_HTML",res.result.payUrl)
//跳轉
uni.navigateTo({url:"/subpages/cashier/webView"})
4.被跳轉頁面
<template><view v-html="htmlContent"></view>
</template><script>
export default {data() {return {htmlContent:""}},onLoad(e) {console.log(e)//獲取參數const html=uni.getStorageSync("ICBC_GW_V3_HTML")console.log(html)this.htmlContent=this.processHtml(html)console.log(this.htmlContent)},mounted() {document.forms[0].submit();},methods: {//僅保留body里面的內容processHtml(html) {// 1. 提取標簽內的內容const bodyMatch = html.match(/<body>([\s\S]*)<\/body>/i);if (!bodyMatch) return '';let bodyContent = bodyMatch[1];// 2. 轉義標簽,防止script中斷bodyContent = bodyContent.replace(/<\/script>/g, '<\\/script>');return bodyContent;}}
};
</script><style></style>