我想在浏览器窗口中打开Blob对象.
这个代码可以在任何地方工作,但iOS Chrome(和IE当然,但我可以解决IE).窗口未重定向到URL(这是正确的或至少与其他浏览器相同).Chrome iOS有任何已知的解决方法吗?
var blob = new window.Blob(['Hello, world!'], {type: 'text/plain;charset=utf-8'});
window.URL = window.URL || window.webkitURL;
var url = window.URL.createObjectURL(blob);
window.location.href = url;
Run Code Online (Sandbox Code Playgroud)
我试过<a href="{blobUrl}>而不是window.location.href但它也不起作用.
大家好,
我试图从websocket服务器(在.NET中)检索图像我将图像作为字节发送然后在客户端检索它,在客户端检索代码(使用canvas和JavaScript):
var c=document.GetElementById("myCanvas");
var ctx=c.getContext("2d");
ws.onmessage=function(evt)
{
var image=new Image();
image.src=URL.createObjectURL(evt.data);
ctx.drawImage(image,0,0);
}
Run Code Online (Sandbox Code Playgroud)
它完美地在firefox上显示图片,但是在Chrome上,它只返回undefined并且不会通过createObjectURL加载图像我使用的是Chrome 18.0.1025.162
任何的想法?
我是学一些javascript,选择一个文件,并使用它来创建可被设置为一个的ObjectURL src一个的html5 video.我是在想这一点镀铬版本18.0.1025.162上ubuntu lucid,并使用本地HTML文件的JavaScript文件和媒体同一文件夹中的文件.
我可以使用input元素选择一个视频文件,当我点击a时play link,执行javascript函数playVideo().
<video id="vid" name='myvid' width="640" height="360" controls="controls">
<source src="test.webm" type="video/webm" />
</video>
<br><a href="#" id="playlnk">Play </a> </li>
<br><input type="file" name="fileselect" id="fselect"> </input>
Run Code Online (Sandbox Code Playgroud)
javascript文件是
$(document).ready(function(){
player=$('#vid').get(0);
$('#playlink').click(function(){playVideo(player);});
});
function setVideoSrc(player,file){
console.log('winurl='+window.URL);
var fileURL = window.URL.createObjectURL(file);
player.src=fileURL;
player.load();
return;
}
function playVideo(player) {
var file=document.getElementById('fselect').files[0];
console.log('you chose:'+file);
if (file==undefined){
console.log('no file chosen');
}else{
console.log('file='+file);
setVideoSrc(player,file);
}
}
Run Code Online (Sandbox Code Playgroud)
当我没有选择任何文件并单击该播放列表时,默认视频播放和控制台日志会显示为no file chosen-as expected.
选择视频文件然后单击playlink时会发生错误.然后该playVideo() …