我在尝试将javascript嵌入到squarespace封面时遇到了问题。该脚本是在按下播放按钮时从vimeo加载随机视频。我当前的网站有相同的播放按钮,但它只播放最新的http://www.andrewlozano.com/
我试图使用的代码就是这个
var videos = [
'238243092',
'235209416',
'187960907',
'187960695',
'187960573',
'187960448',
'187960364',
'187960175',
'187960026',
'187959808',
'187959623',
'187959099',
];
var index=Math.floor(Math.random() * videos.length);
var html='<div class="embed"><iframe src="https://player.vimeo.com/video/' + videos[index] + '" width="100%" height="100%" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe></div>';
document.write(html);
&#13;
但是虽然它在测试时起作用但它在方形空间中不起作用。我收到404错误。
关于可能发生什么或者弄乱它的任何想法?任何指示或建议的方向将不胜感激。
答案 0 :(得分:0)
试试这段代码:
var videos = [
'238243092',
'235209416',
'187960907',
'187960695',
'187960573',
'187960448',
'187960364',
'187960175',
'187960026',
'187959808',
'187959623',
'187959099',
];
var index=Math.floor(Math.random() * videos.length);
var html='<div class="embed"><iframe src="https://player.vimeo.com/video/' + videos[index] + '" width="100%" height="100%" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe></div>';
var body = document.querySelector('body');
body.innerHTML = html;