使用 window.open() 函数时,媒体会在新浏览器 window 中自动播放而不是下载
When using window.open() function, media autoplays in new browser window instead of downloading
我的站点上有各种类型的文件供用户下载。除了 mp3、mp4 等媒体文件外,所有文件都像魅力一样下载。当用户单击 mp3 等下载时,将打开一个新选项卡并播放媒体文件,而不是显示下载弹出窗口……有什么想法吗?
抱歉,我无法在网上找到确切的问题...所有其他答案都以相反的方式显示问题。
function get_dl(e){
var x = $('[name='+ e +']').attr('value');
//sample code from w3schools
if (window.XMLHttpRequest) {
xmlhttp=new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (this.readyState==4 && this.status==200) {
window.open(this.responseText, '_blank');
//This line is where I'm stuck
}
}
xmlhttp.open("GET","getfile.php?q=" + x,true);
xmlhttp.send();
}
所有其他文件都显示下载弹出窗口,媒体文件除外,它们会自动播放而不是下载...
部分:处理二进制数据
function get_dl(e){
var x = $('[name='+ e +']').attr('value');
//sample code from w3schools
if (window.XMLHttpRequest) {
xmlhttp=new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (this.readyState==4 && this.status==200) {
window.open(this.responseText, '_blank');
//This line is where I'm stuck
}
}
//Add these two lines
var arraybuffer = xmlhttp.response;
xmlhttp.responseType = arraybuffer;
xmlhttp.open("GET","getfile.php?q=" + x,true);
xmlhttp.send();
}
这对我来说适用于 MIDI 和 MP3 媒体。还有其他人可以确认它是否对他们有用吗?
我的站点上有各种类型的文件供用户下载。除了 mp3、mp4 等媒体文件外,所有文件都像魅力一样下载。当用户单击 mp3 等下载时,将打开一个新选项卡并播放媒体文件,而不是显示下载弹出窗口……有什么想法吗?
抱歉,我无法在网上找到确切的问题...所有其他答案都以相反的方式显示问题。
function get_dl(e){
var x = $('[name='+ e +']').attr('value');
//sample code from w3schools
if (window.XMLHttpRequest) {
xmlhttp=new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (this.readyState==4 && this.status==200) {
window.open(this.responseText, '_blank');
//This line is where I'm stuck
}
}
xmlhttp.open("GET","getfile.php?q=" + x,true);
xmlhttp.send();
}
所有其他文件都显示下载弹出窗口,媒体文件除外,它们会自动播放而不是下载...
部分:处理二进制数据
function get_dl(e){
var x = $('[name='+ e +']').attr('value');
//sample code from w3schools
if (window.XMLHttpRequest) {
xmlhttp=new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (this.readyState==4 && this.status==200) {
window.open(this.responseText, '_blank');
//This line is where I'm stuck
}
}
//Add these two lines
var arraybuffer = xmlhttp.response;
xmlhttp.responseType = arraybuffer;
xmlhttp.open("GET","getfile.php?q=" + x,true);
xmlhttp.send();
}
这对我来说适用于 MIDI 和 MP3 媒体。还有其他人可以确认它是否对他们有用吗?