最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Make a whole div clickable in order to launch a _blank document - Stack Overflow

programmeradmin2浏览0评论

How can I write the _blank statement in this location.href call?

  <div onclick="location.href='';" style="display:block; height:40px; width:100px; cursor:pointer;"></div> 

Please note: I need to keep the div and treat it as a href container.
When someone clicks it should open a new browser window, not a popup box.

How can I write the _blank statement in this location.href call?

  <div onclick="location.href='http://www.test.com';" style="display:block; height:40px; width:100px; cursor:pointer;"></div> 

Please note: I need to keep the div and treat it as a href container.
When someone clicks it should open a new browser window, not a popup box.

Share Improve this question edited Dec 20, 2010 at 20:05 detonate asked Dec 20, 2010 at 16:54 detonatedetonate 2893 gold badges11 silver badges21 bronze badges 2
  • 1 Howcome you're using a <div> instead of an <a> tag? – Ian Oxley Commented Dec 20, 2010 at 16:57
  • I need to keep the div and treat it as a href block. When someone clicks it should open a new browser window, not a popup box. – detonate Commented Dec 20, 2010 at 17:08
Add a comment  | 

4 Answers 4

Reset to default 13
<div onclick="window.open('http://www.test.com','new_window');" style="display:block; height:40px; width:100px; cursor:pointer;">test</div> 

Use window.open.

or using jquery:

$(this).click(function(){

$(this).open(
{
 width: 400,
 height: 250,
 scrollbars: false
});

});

use an <a> instead of a <div>

<a href="http://www.example.com" target="_blank" style="display:block; width:100px; height:40px;">CONTENT</a>
发布评论

评论列表(0)

  1. 暂无评论