{"id":301,"date":"2011-12-29T17:40:18","date_gmt":"2011-12-29T08:40:18","guid":{"rendered":"http:\/\/www.santoshkori.com\/blog\/?p=301"},"modified":"2012-03-05T21:21:49","modified_gmt":"2012-03-05T12:21:49","slug":"how-to-open-external-links-in-a-new-window-using-jquery","status":"publish","type":"post","link":"https:\/\/www.santoshkori.com\/blog\/how-to-open-external-links-in-a-new-window-using-jquery\/","title":{"rendered":"How to Open external links in a new window using Jquery"},"content":{"rendered":"<p>A simple jQuery trick to open all external links in your site in a new tab or window. First make sure you have jQuery active on your site. if you dont have Jquery in your Site then Download from\u00a0<a href=\"http:\/\/jquery.com\/\" target=\"_blank\" rel=\"noopener\">http:\/\/jquery.com\/<\/a>. and then put below code just before<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n\r\n&lt;script type=&quot;text\/javascript&quot; src=&quot;http:\/\/code.jquery.com\/jquery-1.7.1.min.js&quot; &gt;&lt;\/script&gt;\r\n\r\n&lt;script type=&quot;text\/javacript&quot;&gt;\r\nvar $j = jQuery.noConflict();\r\n\r\n$j(document).ready(function() {\r\n\/\/external attribute\r\n    $j(&quot;a:not(&#x5B;@href*=http:\/\/YOURSITE.com\/])&quot;).not(&quot;&#x5B;href^=#]&quot;)\r\n        .addClass(&quot;external&quot;)\r\n        .attr({ target: &quot;_blank&quot; });\r\n    }\r\n);\r\n&lt;\/script&gt;\r\n\r\n<\/pre>\n<p>That\u2019s it, just make sure you change the http:\/\/YOURSITE.com to your website.<\/p>\n<p>If you like you can remove the var $j = and replace all $j with simply just $<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A simple jQuery trick to open all external links in your site in a new tab or window. First make sure you have jQuery active on your site. if you dont have Jquery in your Site then Download from\u00a0http:\/\/jquery.com\/. and then put below code just before &lt;script type=&quot;text\/javascript&quot; src=&quot;http:\/\/code.jquery.com\/jquery-1.7.1.min.js&quot; &gt;&lt;\/script&gt; &lt;script type=&quot;text\/javacript&quot;&gt; var $j = [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[],"class_list":["post-301","post","type-post","status-publish","format-standard","hentry","category-web-development"],"_links":{"self":[{"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/posts\/301","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/comments?post=301"}],"version-history":[{"count":4,"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/posts\/301\/revisions"}],"predecessor-version":[{"id":303,"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/posts\/301\/revisions\/303"}],"wp:attachment":[{"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/media?parent=301"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/categories?post=301"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.santoshkori.com\/blog\/wp-json\/wp\/v2\/tags?post=301"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}