投稿日:

<main id="exFrame" data-src="ここに呼び出すbeyondページの配信URLを追加"></main> <script> var sbFrameParent = sbFrameParent || {}; (function (_) { _.ExtendFrame = class { constructor(element) { this.el = element; this.url = new URL(this.el.dataset.src); const params = this.url.searchParams; const extend = new URLSearchParams(location.search); ;[...extend.entries()].forEach((param, i) => { params.append(param[0], param[1]); }); let iframe = document.createElement("iframe"); iframe.src = this.url; this.iframe = this.el.appendChild(iframe); window.addEventListener('message', (e) => { this.messageListener(e); }); } messageListener(event) { if (event.origin !== this.url.origin) return; if (event.source !== this.iframe.contentWindow) return; let data = JSON.parse(event.data); switch (data.type) { case null: break; case 'extendParams': let url = new URL(window.location); let params = new URLSearchParams(url.search); [...Object.entries(data.params)].forEach((param) => { if (params.has(param[0])) param[0] = param[0] + '2'; params.set(param[0], param[1]); }); url.search = params; window.history.replaceState('', '', url); break; case 'anchorLink': if (document.getElementById(data.anchor) === null) break; const targetRect = document.getElementById(data.anchor).getBoundingClientRect(); let targetY = window.pageYOffset + targetRect.top; this.smoothScroll(targetY); break; } } smoothScroll(position) { window.scrollTo({ top: position, behavior: 'smooth', }); } } _.init = function () { var frame = new _.ExtendFrame(document.getElementById('exFrame')); } })(sbFrameParent); document.addEventListener('DOMContentLoaded', sbFrameParent.init, false); </script>
HTML
<style> html, body, main { margin: 0; padding: 0; box-sizing: border-box; } #exFrame { width: 100%; height: 100vh; box-sizing: border-box; } #exFrame iframe { width: 100%; height: 100%; vertical-align: bottom; border: 0; box-sizing: border-box; } </style>

Copyright© beautytimes , 2022 All Rights Reserved Powered by AFFINGER5.