【问题标题】:AngularJs: How to check whether a hyperlink is loaded fully and then perform next actionAngularJs:如何检查超链接是否已完全加载,然后执行下一步操作
【发布时间】:2018-06-29 11:06:32
【问题描述】:

问题很简单,我只是想在 ng-click 事件中检查超链接是否已完全加载。

HTML:

<div ng-click='clicked()'>Click me</div>

JS:

$scope.clicked= function() {
window.location='https://firstlink.com';
//
//when above wesbite page is fully loaded then go to below code and load the next link
//
window.location='https://secondlink.com';
}

注意:

我不想检查视图是否加载,我想检查 URL 是否完全加载。 我已经检查了许多关于此的文章和帖子,但我得到的只是如何检查您的 angularjs 应用程序是否已加载。我想要一种方法来检查这些 URL 是否已完全加载。 以下是我已经解决的一些问题:

Post render call for AngularJs

Execute AngularJs controller function on page load

Sending event when angularjs finished loading

Angularjs event to call after content is loaded

【问题讨论】:

    标签: javascript angularjs


    【解决方案1】:

    使用angular.element 等待页面加载

    $scope.clicked= function() {
     window.location='https://firstlink.com';
     //
     //when above wesbite page is fully loaded then go to below code and load the next link
     //
    
     angular.element(function () {
        window.location='https://secondlink.com';
    
     });
    }
    

    【讨论】:

    • 你使用的是哪个角度版本
    • angularjs v 1.6
    【解决方案2】:

    自己找到了解决办法:

    通过使用间隔,我可以先加载第一页,然后等待它完全加载。下面是它的代码:

    window.location='https://firstlink.com';
    var interval = setInterval(function() {     
         if(document.readyState === 'complete') {
    window.location='https://secondlink.com';
    clearInterval(interval);
    
        }    
        }, 100); 
    

    阅读更多关于这个document.readyStatesee this link

    【讨论】:

      猜你喜欢
      • 2018-12-23
      • 1970-01-01
      • 2012-10-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-29
      • 2013-05-18
      相关资源
      最近更新 更多