【JS】プロジェクトが埋め込みモードかどうかを確認する

記事ディレクトリ

  • が埋め込まれているかどうかは、url の検索パラメータ (新しいパラメータ など) によって判断できます。embed
<!-- 正常嵌入 -->
<iframe
      src="https://test.com/#/main?id=66"
      width="100%"
      height="100%"
      frameBorder={0}
/>
<!-- 添加参数判断 -->
<iframe
      src="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');
}

おすすめ

転載: blog.csdn.net/qq_45677671/article/details/134503210