How do I take the optional errMsg parameter on a custom logi

Posted by jsniemi79 on 21-May-2015 07:34

I'm on the private cloud and have a custom login page for our application.  I'd like to use the optional parameter for error messages and display the messages to the user as a browser alert message.  Is this possible?  If so, can you point me in the right direct?

Thanks in advance for your help.

Posted by Gian Torralba on 21-May-2015 08:05

Hello,

You can get it by using a javascript code that gets the http parameter. Please see the code below found at http://stackoverflow.com/questions/827368/using-the-get-parameter-of-a-url-in-javascript

<script>
var param1var = getQueryVariable("param1");

function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = varsIdea.split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  }
  alert('Query Variable ' + variable + ' not found');
}
</script>

Just replace the param1 with the errMsg and then if the parameter has a value do an alert().

Thank you,

Gian

All Replies

Posted by Gian Torralba on 21-May-2015 08:05

Hello,

You can get it by using a javascript code that gets the http parameter. Please see the code below found at http://stackoverflow.com/questions/827368/using-the-get-parameter-of-a-url-in-javascript

<script>
var param1var = getQueryVariable("param1");

function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = varsIdea.split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  }
  alert('Query Variable ' + variable + ' not found');
}
</script>

Just replace the param1 with the errMsg and then if the parameter has a value do an alert().

Thank you,

Gian

Posted by jsniemi79 on 21-May-2015 08:26

Do I just fire this function onload of the window then?

Posted by jsniemi79 on 21-May-2015 10:08

I had to tweak this code a little bit, but I was able to get this to work.  Thanks for your help.

I have this code set in the window.onload function:

var myErrorMsg = '"";

if (str.indexOf("errMsg=") > 0)

 {  

   var res = str.split("?");

   for (var count in res)

   {

     var res2 = res[count].split("=");

   if (res2.length > 1)

       switch(res2[0])

       {

         case 'errMsg': myErrorMsg = res2[1];

 myErrorMsg = myErrorMsg.replace(/\+/g,' ');break;

       }

   }

if (myErrorMsg !== "" && myErrorMsg !== null) {

alert(myErrorMsg);

}

 }

Posted by pvorobie on 21-May-2015 10:54

It is much easier to extract URL parameters on server side assuming you're using technology like JSP or PHP.

This thread is closed