Support Article

HTML rule does not function as expected in Chrome and Firefox

SA-2948

Summary



An application has a screen where a button is configured to call an activity. The button is custom which has an anchor(a) tag with a href to navigate to another URL. The navigation only happens if the activity rule executes correctly. The click works fine in Internet Explorer, however, it does not work in Chrome and Firefox.

Error Messages



Uncaught ReferenceError: ActiveXObject is not defined.

Steps to Reproduce



1. Create a section with a custom button. The button is an anchor tag.
2. Configure the tag to call the function below on 'onclick' event.



function redirectToEAuth(){
    var oSafeURL = new SafeURL("PegaSample.MyCustomActivity");
    var strReturn = httpRequestAsynch(oSafeURL.toURL(), null, 50, 100);
    if (strReturn == "Good") { return true; }
}


3. Add a href attribute to go to another location.
4. Run this in all the 3 browsers.


Root Cause



The method called on the "onclick" event calls another out-of-the-box function httpRequestAsynch.

This method internally uses an old code i.e. new ActiveXObject("Microsoft.XMLHTTP") to create the xmlhttp object which does not work in Chrome/Firefox.

Resolution



Replaced the function configured ‘onclick’ with the below code:

function redirectToEAuth ()
{
try{
var oSafeURL = new SafeURL("PegaSample.MyAct"); // Rename PegaSample.MyAct with your activity name
var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
     return true; //Perform operation after a "good" response is returned from server
    }
  };
xmlhttp.open("GET",oSafeURL.toURL(),false); //Set it to true if this is an async request
xmlhttp.send();
}
catch(e){
// handle your exception here
}
}


Here we are using a synchronous request since we must ensure that the activity is executed before the navigation to href happens.

 
Suggest Edit

Published January 31, 2016 - Updated October 8, 2020


100% found this useful

Have a question? Get answers now.

Visit the Collaboration Center to ask questions, engage in discussions, share ideas, and help others.