Path: csiph.com!news.swapon.de!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Ben Bacarisse Newsgroups: comp.lang.javascript Subject: Re: Open all links in new window Date: Fri, 05 Aug 2016 21:26:14 +0100 Organization: A noiseless patient Spider Lines: 37 Message-ID: <87eg63otcp.fsf@bsb.me.uk> References: <59e0b44d-8ea8-431d-ae12-e7585917f23f@googlegroups.com> <8737mku9we.fsf@bsb.me.uk> <7956cde6-c641-485f-9144-e7ce529f0cd8@googlegroups.com> <87wpjwsj4w.fsf@bsb.me.uk> <56528385-a0f0-4b95-b138-830a6ad9beec@googlegroups.com> <87k2fvr1er.fsf@bsb.me.uk> <878twbqpem.fsf@bsb.me.uk> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="017616aa25f81ec581c44d76d61ba2f3"; logging-data="27594"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/nB1MoL6QXdDn1mZ9o6EpqorNaBrauB0o=" Cancel-Lock: sha1:OsT34u4qstDnMhW//Hih4sV63xI= sha1:C63SAXJB+4ev3/nuRpd5NOnDLPg= X-BSB-Auth: 1.4443c9779b2b1d3df304.20160805212614BST.87eg63otcp.fsf@bsb.me.uk Xref: csiph.com comp.lang.javascript:31081 Chandra writes: > I'm using the below code to load 3rd party urls in a new tab. > > function uu() { > var alllinks = document.links.length; > var linkarray; > var thelink; > > while (alllinks--) { > linkarray = document.links[alllinks]; > thelink = linkarray.href; > > if (thelink.indexOf("http://www.google.co.in/") !== 0) { > linkarray.target = "_blank"; > } > } > } > window.onload = uu; > > Now, I want the sub-domains (micro-sites) also open in a new > window. Like "http://books.google.co.in/", > "https://groups.google.com/". For every 'a' element whose href attribute starts with one of those two example strings, theLink.indexOf("http://www.google.co.in/") will be !== 0 so the target attribute will be set to "_blank". That is what you say you want. If it is not working, it is not working for some reason I could not even guess at. Have you read https://css-tricks.com/use-target_blank/ ? -- Ben.