Solved

Magento Jquery - url open in new window

Posted on 2014-03-09
10
1,236 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
Use Filtering Commands to Process Files in Linux

Learn how to manipulate data with the help of various filtering commands such as `cat`, `fmt`, `pr`, and others in Linux.

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

632 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