Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to redirect to an external URL

Tags:

angularjs

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

like image 674
madh Avatar asked Mar 18 '15 18:03

madh


People also ask

How do I redirect a URL to another URL?

Click the URL Redirects tab. In the upper right, click Add URL redirect. In the right panel, select the Standard or Flexible redirect type. A standard redirect is used to redirect one URL to another.

How do I redirect an external URL in HTML?

The simplest way to redirect to another URL is to use an HTML <meta> tag with the http-equiv parameter set to “refresh”. The content attribute sets the delay before the browser redirects the user to the new web page. To redirect immediately, set this parameter to “0” seconds for the content attribute.

Can you redirect to any URL?

URL redirect (URL forwarding) allows you to forward your domain visitors to any URL of your choice (to a new domain or a different website). You can set 301 (Permanent), 302 (Unmasked), and Masked (URL Frame) redirects for the domain names pointed to BasicDNS, PremiumDNS or FreeDNS.

How redirect external URL in react?

Use the window. location. replace() method to redirect to an external url in React, e.g. window. location.


1 Answers

<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.

like image 92
Alaksandar Jesus Gene Avatar answered Sep 18 '22 18:09

Alaksandar Jesus Gene