如何添加下载链接php或javascript?

时间:2018-01-26 20:53:36

标签: javascript php video

我添加

"sources": <|php echo $file?>

结果

"sources":[{"type": "video/mp4", "label": "HD", "file": "https://video-12345.mp4"}]         }],

我想添加下载按钮

function() {
    window.location.href = " <|php echo $file?>";

结果

function() {
    window.location.href = [{"type": "video/mp4", "label": "HD", "file": "https://video-12345.mp4"}]            }],

所以我只想要视频链接? 结果就像这样...

function() {
    window.location.href = "https://video-12345.mp4";

所以我想点击一下

进行下载

1 个答案:

答案 0 :(得分:0)

如果&lt; | php echo $ file?&gt;产生一个值数组,然后......

var data = [{"type": "video/mp4", "label": "HD", "file": "https://video-12345.mp4"}]; // output of <|php echo $file?>

function myFunction() {
    window.location.href = data[0]['file']; // first item in data array, file property value
}