1

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?

2

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.

  • 1
    Solved with this – domfitty Aug 20 '15 at 17:59
  • 2
    The $_SERVER bit is unnecessary. All Magento blocks (and therefore templates) have an $this->_isSecure() method to check if the current request is secure. You could tidy this up with Mage::getUrl('', array('_secure'=>$this->_isSecure())) – philwinkle Sep 10 '15 at 4:56
2

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);
    }
  • How can i send my EventObserver log message by whatsapp message? @boomer – zus Aug 30 at 7:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.