上传完成后如何重定向到URL Onclick?

问题描述 投票:-1回答:2
$("#fileThumbnail").on("change", function(event) {
  selectedFile = event.target.files[0];

});

function uploadThumb() {

  var filename = selectedFile.name;
  var storageRef = firebase.storage().ref('/Thumbs/' + filename);
  var uploadThumb = storageRef.put(selectedFile);

  uploadThumb.on('state_changed', function progress(snapshot){
    var percentage = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
    uploader.value = percentage;

    $('.thumbsubmit-btn').click(function() {
      window.location.href = 'index.html';
      return false;
    });


  }, function(error) {

  }, function () {

  });
}

我试图在点击时重定向到另一个网址,但是上传完成之后。我怎么做?进度条正在工作,文件也正在上传。只是不知道如何将重定向添加到我的函数中,以便按钮可以上传文件上传完成后,然后触发重定向。

jquery firebase onclick progress-bar onclicklistener
2个回答
2
投票

成功上传后添加重定向


0
投票
$("#fileThumbnail").on("change", function(event) {
  selectedFile = event.target.files[0];

});

function uploadThumb() {

  var filename = selectedFile.name;
  var storageRef = firebase.storage().ref('/Thumbs/' + filename);
  var uploadThumb = storageRef.put(selectedFile);

  uploadThumb.on('state_changed', function progress(snapshot){
    var percentage = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
    uploader.value = percentage;

    $('.thumbsubmit-btn').click(function() {
      window.location.href = 'index.html';
      return false;
    });


  }, function(error) {

  }, function () {
window.location.href = "index.html";
  });
}

所以我想通了。刚刚在最后一个函数上添加了window.location.href =“ index.html”;

© www.soinside.com 2019 - 2024. All rights reserved.