文章目录
- 是否嵌入可以通过
url
的搜索参数去判断,例如新增参数embed
<!-- 正常嵌入 -->
<iframesrc="https://test.com/#/main?id=66"width="100%"height="100%"frameBorder={0}
/>
<!-- 添加参数判断 -->
<iframesrc="https://test.com/?embed=csdn#/main?id=66"width="100%"height="100%"frameBorder={0}
/>
- 在被嵌入的项目接受
embed
参数并进行相应判断和使用
/*** 是否处于嵌入模式*/
export function isEmbed() {const usp = new URLSearchParams(window.location.search);return usp.has('embed');
}
/*** 被哪个平台所嵌入*/
export function getEmbed() {const usp = new URLSearchParams(window.location.search);return usp.get('embed');
}