如何重定向到一个外部URL [英] How to redirect to an external URL

查看:130
本文介绍了如何重定向到一个外部URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当试图重定向到使用外部页 $ window.location.href ,该网页是令人耳目一新,而不是重定向到预期的URL。


解决方案

 < HTML NG-应用=对myApp>
< HEAD>
< /头>
<机身NG控制器=myCtrl>
    &所述p为H.; < A HREF =htt​​ps://www.google.co.in/><按钮和gt;点击我从模板&LT重定向,/按钮>< / A>< / P>
    < p NG点击=myFunction的()> <按钮和gt;点击我从控制器和LT重定向,/按钮>< / P>
&所述; SCRIPT SRC =htt​​ps://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js>&下; /脚本>
<脚本>
    VAR应用= angular.module('对myApp',[]);
    app.controller('myCtrl',函数($窗口,$范围){
        $ scope.myFunction =功能(){
        $ window.location.href ='http://www.google.com'; //你应该在这里有HTTP。
        }
    });
< / SCRIPT>
< /身体GT;
< / HTML>

这为我工作。

When trying to redirect to an external page using $window.location.href, the page is just refreshing and not redirecting to the expected URL.

解决方案

<html ng-app="myApp">
<head>
</head>
<body ng-controller="myCtrl">
    <p> <a href="https://www.google.co.in/"><button>Click me to redirect from template</button></a></p>
    <p ng-click="myFunction()"> <button>Click me to redirect from controller</button></p>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<script>
    var app = angular.module('myApp',[]);
    app.controller('myCtrl',function($window,$scope){
        $scope.myFunction = function(){
        $window.location.href = 'http://www.google.com'; //You should have http here.
        }
    });
</script>
</body>
</html>

This works for me.

这篇关于如何重定向到一个外部URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆