Solved

Magento Jquery - url open in new window

Posted on 2014-03-09
10
1,159 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
  • 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now