等到location.replace之后加载页面

时间:2016-12-22 11:44:08

标签: javascript jquery

我在jquery中使用了以下函数:

$(document).ready(function(){
     $('.folder-action').bind('click', function location() {

        if(parent.document.location.pathname!="/home.php"){
            window.location.replace("home.php");
            location();
         });

         //Other portion of code that need page has been loaded.
     });
});

当替换已被删除时,我需要已经加载页面的所有元素以执行新页面中的代码的其他部分(home.php)。 它尝试过:

setTimeout(function() {location()}, 300);

但它仍然无法奏效。是否可以等到页面的所有元素都被加载?

1 个答案:

答案 0 :(得分:2)

你不能这样做,因为一旦你使用替换功能,浏览器将离开你当前的页面而不再执行代码。

最好的办法是将你的其他部分代码放在home.php的$(document).ready

相关问题