Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1291
  • Last Modified:

Magento Jquery - url open in new window

Hi,

In my top menu the are no of categories.

I added magento url rewrite for my blog .So when i click the category nccf it will take me to my external blog.

Currently it works fine, but i need them to open in new window instead open in same window

The html code below

<li class="level0 nav-4 level-top">
<a href="http://shop.testdomain.org/auction.html" class="level-top">
<span>Auction</span>
</a>
</li>
<li class="level0 nav-5 last level-top">
<a href="http://shop.testdomain.org/nccf.html" class="level-top">
<span>NCCF</span>
</a>
</li>

Open in new window


I googled for it and find few answers but none works for me when i test using firebug.

Thanks
0
magento
Asked:
magento
  • 5
  • 5
1 Solution
 
GaryCommented:
Add target="_blank" into the anchor tag.
0
 
magentoAuthor Commented:
Gary ,

The above html was populated by php script so i cant able to do it for this particular category.

Thanks
0
 
GaryCommented:
How are the links being created? What script?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
magentoAuthor Commented:
I dont know how it was created.

Is it possible to have a jquery when an href is clicked make it open in new window ?

Thanks
0
 
GaryCommented:
Is it just this link?
http://shop.testdomain.org/nccf.html

In your footer somewhere add
<script>
$(function() {
     $('[href="http://shop.testdomain.org/nccf.html"]').prop("target","_blank")
})
</script>

Open in new window

0
 
magentoAuthor Commented:
Modified ur code and then tried the below no luck.

mst( document ).click(function() {
$('[href="http://shop.testdomain.org/nccf.html"]').prop("target","_blank")
});

Open in new window

0
 
GaryCommented:
Why have you changed it - that would fire everytime someone click the page - waste of time and resources.
Is mst your local jquery name?

mst(function() {
     mst('[href="http://shop.testdomain.org/nccf.html"]').prop("target","_blank")
})
0
 
magentoAuthor Commented:
Gary,

What  i have done is , write a rewrite in magento for http://shop.testdomain.org/nccf.html.

When i mouse hover the NCCF link it shows href as http://shop.testdomain.org/nccf.html

But when i click it , it loads in same page and took me to another website url.

I need the same now but in new window.

I will try your code and post back the result tomorrow.

Thanks
0
 
GaryCommented:
This code should work fine - no reason it wouldn't (assuming mst is your jQuery)
mst(function() {
     mst('[href="http://shop.testdomain.org/nccf.html"]').prop("target","_blank")
}) 

Open in new window

If it doesn't work then I'll need to look at the site itself
0
 
magentoAuthor Commented:
Gary,

The above post worked like a charm .

Thank you very much.

BR,
Magento
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now