Solved

Magento Jquery - url open in new window

Posted on 2014-03-09
10
1,210 Views
Last Modified: 2016-03-02
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
Comment
Question by:magento
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
10 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 39916023
Add target="_blank" into the anchor tag.
0
 
LVL 5

Author Comment

by:magento
ID: 39916053
Gary ,

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

Thanks
0
 
LVL 58

Expert Comment

by:Gary
ID: 39916078
How are the links being created? What script?
0
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
LVL 5

Author Comment

by:magento
ID: 39916106
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
 
LVL 58

Expert Comment

by:Gary
ID: 39916112
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
 
LVL 5

Author Comment

by:magento
ID: 39916246
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
 
LVL 58

Expert Comment

by:Gary
ID: 39916256
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
 
LVL 5

Author Comment

by:magento
ID: 39916277
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
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 39916282
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
 
LVL 5

Author Comment

by:magento
ID: 39917510
Gary,

The above post worked like a charm .

Thank you very much.

BR,
Magento
0

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question