猿问

无法成功嵌入/显示 POWR.io 评论

对于遇到这个问题的任何人,希望这能找到你。

我创建了一个快速的小 test.html 文件并在 Chrome 中打开它。它包括以下片段,我无法显示任何内容。

<div class="powr-reviews" id="2753c372_1606181564"></div>
<script src="https://www.powr.io/powr.js?platform=html"></script>

任何和所有帮助将不胜感激。


Cats萌萌
浏览 147回答 1
1回答

缥缈止盈

var theFrame=document.createElement('iframe')theFrame.src="https://www.powr.io/reviews/i/26790199#page"document.body.appendChild(theFrame)//document.appendChild isn't reliable since it says some ONLY ALLOWS ONE APPENDAGE or something like that//the above code only works if cors doesn't block you, meaning that your source for this would be from powr.io as well(THIS IS A SANDBOX SO IT GETS BLOCKED BECAUSE OF ORIGIN DIFFERENCE)//if i run the code below, it works on newtab(if u pop up the console paste and enter)document.write('<div class="powr-reviews" id="2753c372_1606181564"></div>')var x=document.createElement('script')x.src="https://www.powr.io/powr.js?platform=html"document.body.appendChild(x)现在我有一个小的repl来表明你的 2 行工作,但如果你的源(在客户端运行它时的原点)是文件,它就不起作用现在在下面,我尝试模仿代码到底做了什么JavaScript 示例及其repl//iframe loaderfunction iframer(sourceUrl){  document.body.innerHTML="" //makes sure ONLY this loads  var iframe = document.createElement('iframe');  iframe.src = sourceUrl;  iframe.width=screen.availWidth;  iframe.height=screen.availHeight;  iframe.style="border: solid transparent";  document.body.appendChild(iframe);  return iframe;}var myFrame=iframer("https://www.powr.io/reviews/i/26790199#page")console.log(myFrame)HTML 示例及其repl<meta http-equiv="refresh" content="0;URL='https://www.powr.io/reviews/i/26790199#page'">
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答