How to redirect the page by click the button on service portal?

sri83
Tera Guru

Hi Team,

 

I have created the button on portal form. When i click the button, it should redirect to another page but the script is not working and redirection is not happening please help me.

 

Code:

Client Controller:

var app = angular.module('Demo', []);
app.controller('Sample', function($scope, $window, $location) {
$scope.location = function(){
var url = "https://www.XXXXXXXXXXX.com/";
$window.location.href = url;
}
});

 

HTML:

 

<div ng-app="Demo" ng-controller="Sample">
<button ng-click="location()">Click here</button>
</div>

 

sri83_0-1669618109855.png

 

 

Regards,

Sri

9 REPLIES 9

RaghavSh
Kilo Patron

Try below:

HTML:

<div >
<button ng-click="c.location()">Click here</button>
</div>

 

client:

var c = this;

c.location = function()

{

window.location.href = "https://www.XXXXXXXXXXX.com/";

}


Please mark the answer correct/helpful accordingly.


Raghav
MVP 2023
LinkedIn

Hi Raghv,

 

Thanks for the quick reply.

I have tried the above script but it's not working for me. Please do suggest

 

sri83_0-1669619541778.png

 

This should work, you have removed the OOB code of client script, can you add that and try?

Also Demo, is that the name of your portal?

Try to add alert as well in c.location function in client controller


Raghav
MVP 2023
LinkedIn

Akshay64
Tera Contributor

Hi,

 

It should work,below i have passed instance url just for testing and it's navigating to instance page as expected. kindly check the url/page which you passed in client script. 

Akshay64_0-1669626361291.png