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?

asked Aug 19, 2015 at 21:49
1

2 Answers 2

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.

answered Aug 19, 2015 at 22:10
2
  • 1
    Solved with this Commented Aug 20, 2015 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())) Commented Sep 10, 2015 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);
 }
philwinkle
35.8k5 gold badges92 silver badges146 bronze badges
answered Aug 19, 2015 at 23:54
1
  • How can i send my EventObserver log message by whatsapp message? @boomer Commented Aug 30, 2019 at 7:47

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.