{"id":670,"date":"2012-11-29T10:28:35","date_gmt":"2012-11-29T10:28:35","guid":{"rendered":"http:\/\/codeatelier.wordpress.com\/?p=398"},"modified":"2012-11-29T10:28:35","modified_gmt":"2012-11-29T10:28:35","slug":"how-to-open-link-in-new-tab-using-javascript","status":"publish","type":"post","link":"https:\/\/codethataint.com\/blog\/how-to-open-link-in-new-tab-using-javascript\/","title":{"rendered":"how to open link in new tab using javascript"},"content":{"rendered":"<p><strong>Method 1<\/strong><\/p>\n<pre>\nfunction open_in_new_tab(url )\n{\n  window.open(url, '_blank');\n  window.focus();\n}\n<\/pre>\n<p><strong>Method 2<\/strong><\/p>\n<pre>\n $('a').click(function() {\n  $(this).attr('target', '_blank');\n });\n<\/pre>\n<p><strong>Method 3<\/strong><\/p>\n<pre>\n $(document).ready(function() {\n   $('#NewTab').click(function() {\n        $(this).target = \"_blank\";\n        window.open($(this).prop('href'));\n        return false;\n   });\n});\u200b\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Method 1 function open_in_new_tab(url ) { window.open(url, &#8216;_blank&#8217;); window.focus(); } Method 2 $(&#8216;a&#8217;).click(function() { $(this).attr(&#8216;target&#8217;, &#8216;_blank&#8217;); }); Method 3 $(document).ready(function() { $(&#8216;#NewTab&#8217;).click(function() { $(this).target = &#8220;_blank&#8221;; window.open($(this).prop(&#8216;href&#8217;)); return false; }); });\u200b<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"class_list":["post-670","post","type-post","status-publish","format-standard","hentry","category-javascript"],"_links":{"self":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/670","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/comments?post=670"}],"version-history":[{"count":0,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/670\/revisions"}],"wp:attachment":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/media?parent=670"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/categories?post=670"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/tags?post=670"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}