导航菜单中的magento javascript:void(0)

magento javascript:void(0) in navigation menu

本文关键字:void javascript 菜单 magento 导航      更新时间:2023-09-26

很长一段时间以来,我一直在尝试将Javascript:void(0)添加到我的magento网站的导航栏中。我读了很多关于这个主题的文章,几乎所有的文章都说我应该编辑

/app/code/core/Mage/Coatalog/Block/Navigation.php,或者将其复制到本地文件夹中并在那里进行编辑。

这是我遵循的一种流行方式;

To remove url, href functionality of the top menu categories, you can take the following steps:
Create some folder as this path: app/code/local/Mage/Catalog/Block
Copy file Navigation.php from app/code/core/Mage/Catalog/Block to 
app/code/local/Mage/Catalog/Block
Go to function _renderCategoryMenuItemHtml()
Replace this code
$html[] = '<a href="'.$this->getCategoryUrl($category).'"'.$linkClass.'>';
$html[] = '<span>' . $this->escapeHtml($category->getName()) . '</span>';
$html[] = '</a>';
with this code
if($category->getLevel()== 2 && $hasActiveChildren) {
        $html[] = '<a href="[removed]void(0);"'.$linkClass.'>';
        $html[] = '<span>' . $this->escapeHtml($category->getName()) . '</span>';
        $html[] = '</a>';
} else {
        $html[] = '<a href="'.$this->getCategoryUrl($category).'"'.$linkClass.'>';
        $html[] = '<span>' . $this->escapeHtml($category->getName()) . '</span>';
        $html[] = '</a>';
}

但它对我不起作用。奇怪的是,即使我删除/app/code/core/Mage/Catalog/Block/Navigation.php,导航菜单也能正常工作。如果它得到了工作的代码,我不知道。

也许你有一个想法可以帮助我。我只想把Javascript:void(0)放在导航菜单中。

我觉得是缓存或Magento编译器的问题。我建议你从magento管理员做以下步骤。

  1. 转到admin->System->Cache Management并清除/刷新所有缓存

  2. 转到admin->System->Tools->Compilation。检查编译是否已启用,然后禁用它,再次清除缓存并运行编译过程

我也在寻求解决这个问题,我认为问题是你链接的代码只能在1.7上工作,而不能在1.9上工作?

我提出的解决方案

Topmenu.phpapp'code'core'Mage'Page'Block'Html复制到第131行的app'code'local'Mage'Page'Block'Html替换:

$html .= '<li ' . $this->_getRenderedMenuItemAttributes($child) . '>';
$html .= '<a href="' . $child->getUrl() . '" ' . $outermostClassCode . '><span>'
            . $this->escapeHtml($child->getName()) . '</span></a>';

        if ($child->hasChildren()) {
            $html .= '<li ' . $this->_getRenderedMenuItemAttributes($child) . '>';
            $html .= '<a href=''javascript:void(0);''><span>'
                . $this->escapeHtml($child->getName()) . '</span></a>';
        }
        else{
           $html .= '<li ' . $this->_getRenderedMenuItemAttributes($child) . '>';
           $html .= '<a href="' . $child->getUrl() . '" ' . $outermostClassCode . '><span>'
            . $this->escapeHtml($child->getName()) . '</span></a>';
        }

希望这能有所帮助。