在另一个函数完成后使用javascript重定向到另一个页面

在另一个函数完成后使用javascript重定向到另一个页面,javascript,Javascript,在用javascript播放动画后,我想重定向到lilas.com网站。我不太懂javascript,需要帮助 此handleComplete功能完成后,我想重定向并等待3秒钟 function handleComplete() function handleComplete() { exportRoot = new lib.Lilas(); stage = new createjs.Stage(canvas); stage.addChild(exportRoot);

在用javascript播放动画后,我想重定向到lilas.com网站。我不太懂javascript,需要帮助

handleComplete
功能完成后,我想重定向并等待3秒钟

function handleComplete()

function handleComplete() 
{ 
   exportRoot = new lib.Lilas(); 
   stage = new createjs.Stage(canvas); 
   stage.addChild(exportRoot);  
   createjs.Ticker.setFPS(lib.properties.fps);     
   createjs.Ticker.addEventListener("tick", stage); //Code to support hidpi screens and responsive scaling. 
  (function(isResp, respDim, isScale, scaleType) 
   {    
     var lastW, lastH, lastS=1; 
     else if(scaleType==1) 
     {  
       sRatio = Math.min(xRatio, yRatio);   
     }  else if(scaleType==2) 
     {  sRatio = Math.max(xRatio, yRatio);  
     }  
    } 
   })(true,'both',true,2);  }

您可以使用
setTimeout()
进行此操作

setTimeout(function(){ window.location.href="http://www.lilas.com" }, 3000);

您可以使用
setTimeout()
进行此操作

setTimeout(function(){ window.location.href="http://www.lilas.com" }, 3000);

您可以使用
settimeout()
等待并在函数执行后调用

javascript在单线程中运行,因此重定向将在函数执行后发生

function handleComplete();
window.setTimeout(function(){

    // Move to a new location or you can do something else
    window.location.href = "http://www.lilas.com";

}, 3000);

您可以使用
settimeout()
等待并在函数执行后调用

javascript在单线程中运行,因此重定向将在函数执行后发生

function handleComplete();
window.setTimeout(function(){

    // Move to a new location or you can do something else
    window.location.href = "http://www.lilas.com";

}, 3000);

它取决于执行什么
handleComplete
函数

如果这个函数执行一个非异步代码,您可以在
setTimeout
中调用另一个函数,就像Helmal和Ameya在回答中所说的那样


如果
handleComplete
执行一个异步进程,您必须等待该进程完成其执行,然后等待3秒钟执行另一个函数。

这取决于
handleComplete
函数执行的内容

如果这个函数执行一个非异步代码,您可以在
setTimeout
中调用另一个函数,就像Helmal和Ameya在回答中所说的那样


如果
handleComplete
执行一个异步进程,您必须等待该进程完成它的执行,然后等待3秒钟来执行另一个函数。

看来您称为“handleComplete”的函数是异步函数,这意味着它与时间不协调,要解决此问题,您有两种方法:

1-您需要计算执行该函数所需的时间,然后使用setTimeout函数。 例如,如果功能需要在平均50毫秒内完成,则可以执行以下操作:

window.setTimeout(function(){

    // Your redirect is here
    window.location.href = "lilas.com";

}, 3050);
function handleComplete( *args*, callback) {

    // the function code, just change return sentence with this line
    return callback();
}

// the call will be like
handleComplete(*args*, function() {
    window.setTimeout(function(){

        // Your redirect is here
        window.location.href = "lilas.com";

    }, 3000);
});
2-第二种更复杂但更有效的方法是使用回调思想,您需要将handleComplete函数的实现和调用更改为如下所示:

window.setTimeout(function(){

    // Your redirect is here
    window.location.href = "lilas.com";

}, 3050);
function handleComplete( *args*, callback) {

    // the function code, just change return sentence with this line
    return callback();
}

// the call will be like
handleComplete(*args*, function() {
    window.setTimeout(function(){

        // Your redirect is here
        window.location.href = "lilas.com";

    }, 3000);
});

您的函数“handleComplete”似乎是异步函数,这意味着它与时间不协调,要解决此问题,有两种方法:

1-您需要计算执行该函数所需的时间,然后使用setTimeout函数。 例如,如果功能需要在平均50毫秒内完成,则可以执行以下操作:

window.setTimeout(function(){

    // Your redirect is here
    window.location.href = "lilas.com";

}, 3050);
function handleComplete( *args*, callback) {

    // the function code, just change return sentence with this line
    return callback();
}

// the call will be like
handleComplete(*args*, function() {
    window.setTimeout(function(){

        // Your redirect is here
        window.location.href = "lilas.com";

    }, 3000);
});
2-第二种更复杂但更有效的方法是使用回调思想,您需要将handleComplete函数的实现和调用更改为如下所示:

window.setTimeout(function(){

    // Your redirect is here
    window.location.href = "lilas.com";

}, 3050);
function handleComplete( *args*, callback) {

    // the function code, just change return sentence with this line
    return callback();
}

// the call will be like
handleComplete(*args*, function() {
    window.setTimeout(function(){

        // Your redirect is here
        window.location.href = "lilas.com";

    }, 3000);
});

handleComplete()执行什么?能否共享
handleComplete()
的反定义?它是从Adobe Animate CC导出的自动生成的create.js动画函数。handleComplete()执行什么?能否共享
handleComplete()的反定义
?这是一个从Adobe Animate CC导出的自动生成的create.js动画功能。我按照您的建议放置了它,但它会在动画处理完成之前重定向。我是否应该附上整个函数供您查看?@WasiRahman请浏览此链接。你可能会在那里得到一些东西
http://www.createjs.com/docs/easeljs/classes/EventDispatcher.html#method_on
这是动画@ameya的文件,我想你可以使用
timeout
属性。请检查一下
http://www.createjs.com/docs/easeljs/classes/Ticker.html
我已根据您的建议放置,但它会在动画手册完成之前重定向。我是否应该附上整个函数供您查看?@WasiRahman请浏览此链接。你可能会在那里得到一些东西
http://www.createjs.com/docs/easeljs/classes/EventDispatcher.html#method_on
这是动画@ameya的文件,我想你可以使用
timeout
属性。请检查一下
http://www.createjs.com/docs/easeljs/classes/Ticker.html
我计算了时间,发现12000没问题。我计算了时间,发现12000没问题。