createObjectURL在Chrome中返回undefined

Rup*_*psa 10 javascript video upload file

尝试使用createObjectDataURL更改视频源文件.它适用于Firefox,但不适用于Chrome(版本12.0.742.122 m).代码不会抛出任何错误,但会为createObjectDataURL返回undefined.我尝试了所有的可能性,但它总是返回undefined.

<!DOCTYPE html>
<html>
<head>
<title>Check CreateObjectURL</title>
</head>
<script type="text/javascript" language="javascript">

window.URL = window.URL || window.webkitURL;

function ChangeProperty()
{
        var v = document.getElementById("myvideo");
        var file = document.getElementById("fileControl").files[0];
        v.setAttribute("src",window.URL.createObjectURL(file));
}
</script>
<body>
<div >
    <video id="myvideo" src="movie.ogg" controls ></video>
    <input type="file" id="fileControl" /> 
    <button id="btnprops" onClick="ChangeProperty()" >update</button>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

请帮我.它已经花了很多时间.提前致谢.

小智 4

当我在 Chrome 中将页面作为本地文件打开时,我遇到了同样的问题。我必须使用 Apache 并通过 localhost 打开它。