Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
90 views
in Technique[技术] by (71.8m points)

javascript - MeteorJs link to download a mp3 file

This NodeJs Meteor app displays a li to the user when clicked it creates a button to download a mp3 file, but clicking the button failed to download. Any idea why and how to fix it?

The app is running locally on a Window10 which is running 2 servers, nodeJs for Meteor and xampp Apache to serve the audio files. When the link is copied and pasted in a new tab it plays the .mp3 file fine.

Here is the link copied from the browser Element inspect section. onclick="window.location.href=http://localhost/Audio/1 LIBROS DE LA/1 Antiguo/1 sis/1 Cap.1 v.1.mp3"

function downloadLink(link){
  let download = document.createElement('div')
  download.setAttribute('id', 'right')

  let button = document.createElement('input')
  button.setAttribute('type', 'button' )
  button.setAttribute('value', 'Download file' )
  button.setAttribute('onClick', 'window.location.href='+link )

  download.appendChild(button)
  return download
}

Template.tree.events({
  'click li'(event){
    let parent = document.createElement('div')
    let download = downloadLink(link)
    parent.appendChild(download)
    $(event.target).append(parent)    
  }
})
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <h1>Welcom Audio!</h1>
  {{> tree}}  
</body>

<template name="tree">

  <ol>
    {{#each item in result}}
      <li class="pointer" data-type={{item.type}} data-order={{item.order}}>{{item.title}}</li>
    {{/each}}
  </ol>
</template>
question from:https://stackoverflow.com/questions/66055385/meteorjs-link-to-download-a-mp3-file

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...