|
|
@@ -240,6 +240,21 @@ const processedSrcDoc = computed(() => {
|
|
|
for (const [pattern, replacement] of CDN_RULES) {
|
|
|
html = html.replace(pattern, replacement)
|
|
|
}
|
|
|
+ // 注入 <base href>:srcdoc 内相对路径资源需要基于原始页面 URL 解析
|
|
|
+ const baseHref = props.elementInfo.curl
|
|
|
+ if (baseHref && !/<base\s/i.test(html)) {
|
|
|
+ const safeHref = baseHref.replace(/"/g, '"')
|
|
|
+ const baseTag = `<base href="${safeHref}">`
|
|
|
+ if (/<head[^>]*>/i.test(html)) {
|
|
|
+ html = html.replace(/<head[^>]*>/i, match => `${match}${baseTag}`)
|
|
|
+ }
|
|
|
+ else if (/<html[^>]*>/i.test(html)) {
|
|
|
+ html = html.replace(/<html[^>]*>/i, match => `${match}<head>${baseTag}</head>`)
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ html = `<head>${baseTag}</head>${html}`
|
|
|
+ }
|
|
|
+ }
|
|
|
return html
|
|
|
})
|
|
|
|