Friday, December 7, 2012

Getting Salesforce URL using Javascript in Visualforce Page

This will return the salesforce base URL which can be used visualforce pages

function salesforcebaseURL()
{

    var d = $gc(location).attr('href');

    pathArray = d.split( '/' );

    var Protocol = pathArray[0]; 

    var host = pathArray[2];

    return Protocol+'//'+host;

}

if we need to call any other visualforce page append with the "apex/page name"

var URL = salesforceURL()+'apex/samplepage';