• N M 17
  • NEWBIE
  • 0 Points
  • Member since 2015


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
I have a relatively simple S-control that is manifesting some bizarre problems I can't easily reproduce. The only thing I get is a message from Salesforce:
 Invalid Page Redirection
    The page you attempted to access has been blocked due to an outside website or an improperly coded link or button. Please contact your Salesforce Administrator for assistance.

  Click here to return to the previous page.

The only thing I can think of is that there is something wrong with the JS I pulled off the web to process out the retUrl parameter from the URL my S-control is fed.

Code:
//function to decode given URL
function decodeUrl(url)
{
   /* When decoding the URL we will do the following:

           1.) Replace + with ' '
           2.) Replace %xx with equivalent character
           3.) Put [—] in output if %xx is invalid.
   */

   //string holding our hexadecimal values
   var hexValues = "0123456789ABCDEFabcdef"; 
   //value to hold the initial URL value
   //variable to hold the final URL value
   var returnURL = "";
   //counter variable
   var count = 0;
   plainUrl = url;
   //start looping through each character in the URL
   while (count < plainUrl.length) 
   {
      //get each character on each iteration
      var charValue = plainUrl.charAt(count);
      //determine the value of the character
      switch(charValue)
      {
         //if the character is a plus sign (+) then append a space
         case "+":
             returnURL += " ";
             //increment our counter
             count++;
             break;
         //if the character is a percent sign we have a little more work to do
         case "%":
             //first determine if we have a valid character (one that is in our list)
             if (count < (plainUrl.length - 2) && hexValues.indexOf(plainUrl.charAt(count+1)) != -1 && hexValues.indexOf(plainUrl.charAt(count + 2)) != -1 ) 
             {
                 //its a valid character so unescape it
          returnURL += unescape(plainUrl.substr(count,3));
                 //increment the counter by 3
          count += 3;
      } 
             else 
             {
          //we have a bad character so append [–]
          returnURL += "%[˜]";
          count++;
             }
             break;
         default:
             //default value is to append the current character
             //to the return value
             returnURL += charValue;
             count++;
             break;
      }
    }
   //return the final decoded URL
   return returnURL;
}

function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\™&]"+name+"=([%^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( decodeUrl(window.parent.location.href) );
  var result = decodeUrl(window.parent.location.href).substr(results.index+8,24);
  if( results == null )
    return "";
  else
    return result;
}


 And the actual call is: window.opener.location.href = "https://na1.salesforce.com/"+gup("retURL");

  • October 22, 2008
  • Like
  • 0