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?
-
Try out this simple extension magecomp.com/magento-whatsapp-contact.htmlGaurav Jain– Gaurav Jain2018年01月01日 10:03:52 +00:00Commented Jan 1, 2018 at 10:03
2 Answers 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
-
2The
$_SERVERbit 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 withMage::getUrl('', array('_secure'=>$this->_isSecure()))philwinkle– philwinkle2015年09月10日 04:56:22 +00:00Commented Sep 10, 2015 at 4:56
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? @boomerzus– zus2019年08月30日 07:47:51 +00:00Commented Aug 30, 2019 at 7:47