我想在我的网站上加入一个 Spreadshirt Shop(联属网络营销)。
为此,我想集成 Creator Tool 和购物车,到目前为止这也是有效的。
它通过 Javascript 作为 IFrame 集成。
现在双方都有一个显示 Spreadshirt Logo 的预加载器,但在加载工具之前,我会让访问者看到我的 Logo 。
因为我不认为这会在 iframe 中被操纵,所以我有另一个想法。
我想从页面 View 中创建一个带有 z-index 的单独 DIV,直到页面加载到 iFrame 中。为此,我必须在 Creator Tool 的 iFrame 中显示 DIV,在购物车中显示 DIV 监视器,一旦这些项目就位,就禁用我的 DIV。
不幸的是我只能使用 HTMl 和 PHP。有人可以帮助我吗,例如使用 Javascript 或 jQuery?
所以,我认为 window.parent.postMessage 是你的关键:https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage
pageZ1.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Z1</title>
<style>
iframe{ width: 200px; height: 200px;}
.noDisplay { display: none;}
</style>
</head>
<body>
<h4>main page</h4>
<div id="logo">LOGO</div>
<iframe src="PageZ2.html" frameborder="0"></iframe>
<script>
window.onmessage=e=>{
if (e.data==='load End') logo.className = 'noDisplay'
}
</script>
</body>
</html>
PageZ2.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Z2</title>
</head>
<body>
<h6>page Z 2</h6>
<button id="btLoadEnd">end loading event of something</button>
<script>
btLoadEnd.onclick=_=>{
window.parent.postMessage('load End',"*");
}
</script>
</body>
</html>