Loading...

How to open a menu link in a new tab/window

Daniel C. Published on 03 October, 2011

There isn't an easy option to fine tune the control over the menu links, either in the admin panel or in the BigCommerce's templates, this is why you need to make use of javascript to customize the look and feel.

When clicking on a menu page it will open in the current window by default. There are situation when opening in a new tab/window is required. This post will show you how to open a web page in a new window/tab. Just copy-paste the following script in footer.html template file.


bigcommerce pages menu

<script type="text/javascript">
$(document).ready(function() {

$('#Menu ul li a').each(function() { if($(this).find('span').html() == 'theNameOfThePage') {

    <span class="nx">$</span><span class="p">(</span><span class="k">this</span><span class="p">).</span><span class="nx">attr</span><span class="p">(</span><span class="s1">&#39;target&#39;</span><span class="p">,</span> <span class="s1">&#39;_new&#39;</span><span class="p">);</span>
<span class="p">}</span>

});

}); </script>


NOTE

  1. theNameOfThePage must be the exact name how it appears in the control panel. Only the page specified by theNameOfThePage will be opening in a new tab.
  2. to open the page in a new window, replace _new with _blank. It depends on the browser whether the page will be opened in a new window or not.

The code can be auto-generated by entering the page name in the field below:

Page Name: OK

<script type="text/javascript">
$(document).ready(function() {

$('#Menu ul li a').each(function() {
    if($(this).find('span').html() == 'theNameOfThePage') {

        $(this).attr('target', '_new');
    }
});

});
</script>

Test it yourself!
Enter the page name you want to open in a new tab/window and click OK.

Page Name: OK


If you'd like to make use of some other javascript hacks for your store, but do not know how to do it, them why not request a quote from us? Our team will be able to provide BigCommerce template designs at a fair price.
Daniel C. Published on 03 October, 2011