Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> JavaScript

เลือกใช้ window.URL.createObjectURL() หรือ window.webkitURL.createObjectURL() ตามเบราว์เซอร์

เพื่อเลือก ให้กำหนด wrapper function:

function display(file) {
  if (window.webkitURL) {
    return window.webkitURL.createObjectURL(file);
  } else if (window.URL && window.URL.createObjectURL) {
    return window.URL.createObjectURL(file);
  } else {
    return null;
  }
}

หลังจากนั้นตั้งค่าเพื่อ cross-browser:

var url = display(file);