0

Hi,

Please look at this code

 <div class="box">
 <a href="http:www.google.com"  target="_blank">click</a>
 </div>

 //css

 .box { width:250px; height:250px;  border:1px solid red; }

 //script
 $('.box').click(function(){
    $(this).find('a').trigger('click');
 });

How to set target _blank when clicking the div.box.
click is working fine but it opens the page in same window.

Can you anyone have idea..

Thanks in advance,
Developer

4
Contributors
11
Replies
25
Views
4 Years
Discussion Span
Last Post by paulkd
0

Your href value is incorrect, it should start http://

You don't need the JS to open a new window the (deprecated) target atrribute should take care of that for you.

0

So, as you can see we are a bit confused as to this approach. If you can provide clarification on what you are trying to implement, better guidance can be provided.

If you are simply trying to create a box that acts like a link, try this approach. Simply use an anchor element, but style it with display:block. See this example..

<!DOCTYPE html>
<html>
<head>
<title>Demo</title>
<style> 
 .box { 
 width:250px; 
 height:250px;  
 border:1px solid red; 
 display:block;
 }
</style>
</head>
<body>
 <a class="box" href="http://www.google.com"  target="_blank">click</a>
</body>
</html>

This approach creates the look and feel as your sample code, but without the div element and the _blank works as expected.

Hope this helps..

Edited by JorgeM

0

Hi thanks for all,

I am not trying to create a box, Its like a article section.
What we will do is, we will get the article link and append to the parent div(.box) so ultimately it works.But target is not working.

Let me ask you straightly

<div class="box">

</div>


//css
.box { width:250px; height:250px; border:1px solid red; }
//script

var href = 'http://www.google.com';
$('.box').click(function(){
 window.location.href= href;   //This should open in target _blank 
});

Is that possible, Hope now question will be clear

Thanks in advance

Developer

0

Dear paulkd,

Please check out the link,
I am targeting the below div, link should be inside the div with class .news-title and it should open in new window.

<div class="article-content"></div>
0

I think you might just be able to add

$(".article-content").find("a.news-title").attr("target","_blank");

to your js file.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.