Q: Base url and Whatsapp button (script embed with secure and unsecure url) I'm trying to integrate Whatsapp button on my magento website.
I added the following code to my head.phtml
<script type="text/javascript">if(typeof wabtn4fg==="undefined"){wabtn4fg=1;h=document.head||document.getElementsByTagName("head")[0],s=document.createElement("script");s.type="text/javascript";s.src="<?php echo Mage::getBaseUrl() ?>js/whatsapp/whatsapp-button.js";h.appendChild(s);}</script>

I get the following console error when I visit secure url pages because .js url is always http://

Mixed Content: The page at
  'https://www.mywebsite......' was loaded over
  HTTPS, but requested an insecure script
  'http://www.mywebsite..../whatsapp-button.js'. This
  request has been blocked; the content must be served over HTTPS.

Is there a way to get secure base url on secure pages and unsecure base url on unsecure pages?

A: You could try the solution posted here: https://stackoverflow.com/questions/1411531/magento-ssl-links
Mage::getUrl('', array('_secure'=>($_SERVER['SERVER_PORT']==443?true:false)))

That way it will return a secure or insecure link depending on whether or not the current page is secure.

A: Simply using a relative protocol of // instead of <?php echo Mage::getBaseUr() ?> will suffice. Or simply use HTTPS for both HTTP and HTTPS, as HTTP won't throw mixed protocol warnings.
<?php echo Mage::getBaseUrl('', true) ?>
 public static function getBaseUrl($type = Mage_Core_Model_Store::URL_TYPE_LINK, $secure = null)
    {
        return self::app()->getStore()->getBaseUrl($type, $secure);
    }



*

*Mage::getBaseUrl() vs Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB)
