I am trying to redirect users when they click on a button via javascript. So something like this :
top.location=url;
Normally this redirects you to the specified "url" but strangely enough user is being redirected to same page.
Is there a way to redirect a user using javascript that works with Primefaces ? Not sure why primefaces is interfering.
<div>
<p:commandButton value="Cancel" onclick="javascript:$.fn.RedirectMe('http://google.com')" />
</div>
Javascript:
$.fn.RedirectMe = function(url) {
var confirmBox=confirm("Are you sure ?");
if (confirmBox==false)
{
return false;
}
if(typeof(url) =="undefined" || url == null || url==""){
top.location=top.location;
}else{
url = encodeURI(url);
top.location=url;
}
};