Я объединил некоторые jQuery и PHP в своей функции. Google Chrome отображает код правильно, и результат такой, как и ожидалось, однако Opera или Firefox выдают ошибку Uncaught SyntaxError: missing ) after argument list
.
Часть PHP просто проверяет, вошел ли клиент в мой Magento магазин, а затем добавив правильный div.
PHP / JS:
AddWelcomeBar();
jQuery(window).resize(function() {
AddWelcomeBar()
});
<?php $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customerSession = $objectManager->get('Magento\Customer\Model\Session');
$customerName = $customerSession->getCustomer()->getName();
?>
function AddWelcomeBar() {
var innerWidth = window.innerWidth;
if (innerWidth < 850) {
<?php if ($customerSession->isLoggedIn()) { ?>
var customer = "<?php echo $customerName ?>";
var welcomebar = jQuery(".welcomebar");
if (welcomebar.length == 0) {
jQuery(".section-item-content").prepend("<div class='welcome-message-mobile welcomebar'>Welcome," + customer + "</div>");
<?php } else { ?>
jQuery(".section-item-content").prepend("<div class='welcome-message-mobile welcomebar'>10% OFF YOUR 1ST ORDER: CODE 'VV10'</div>");
<?php } ?>
} else if (innerWidth > 850) {
jQuery(".section-item-content > .welcomebar").remove();
jQuery(".section-item-content").show();
}
}
}
HTML:
<div class="section-item-content">
</div>
Если я удаляю последнее закрытие }
, то оно работает на Opera и Firefox, но Google Chrome говорит, что отсутствует }
. Есть идеи?
По сути, устранение проблемы в одном браузере приводит к поломке кода в другом.