?
Solved

Magento Jquery - url open in new window

Posted on 2014-03-09
10
Medium Priority
?
1,270 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
Quiz: What Do These Organizations Have In Common?

Hint: Their teams ended up taking quizzes, too.

 
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 2000 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn how to dynamically set the form action using jQuery.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
Suggested Courses

719 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