Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #31008

Re: Open all links in new window

Path csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From Osmo Saarikumpu <osmo@weppipakki.com>
Newsgroups comp.lang.javascript
Subject Re: Open all links in new window
Date Tue, 2 Aug 2016 06:44:17 +0300
Organization A noiseless patient Spider
Lines 23
Message-ID <nnp4u4$j4t$1@dont-email.me> (permalink)
References <e1ab8ac7-2ef0-4f29-adcc-9276edc0dddf@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 7bit
Injection-Date Tue, 2 Aug 2016 03:44:04 -0000 (UTC)
Injection-Info mx02.eternal-september.org; posting-host="07bd8b665f8672af6551e67a21265687"; logging-data="19613"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18+eoi89EWkfrDudr2MDsJR"
User-Agent Mozilla/5.0 (Windows NT 6.3; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0
In-Reply-To <e1ab8ac7-2ef0-4f29-adcc-9276edc0dddf@googlegroups.com>
Cancel-Lock sha1:qVSBANt7mCsOC7UUQGAjtfOtaPs=
Xref csiph.com comp.lang.javascript:31008

Show key headers only | View raw


On 01/08/2016 09:37, csakkoni@gmail.com wrote:
> I have a website www.xyzabc.com (dummy site mentioned) and on the tutorials web page I have 100+ urls. Few assets are linked to my site and few are 3rd party links. I need a script which excludes my links and all 3rd party links are opened in a new tab even if I do not add target="_blank" or onclick().The Code should not be applied manually on all links, it should be one simple code that can be updated in a JS file.

Perhaps the following sketch may get you started:

function uu() {
   var alllinks = document.links.length;
   var linkarray;
   var thelink;

   while (alllinks--) {
   linkarray = document.links[alllinks];
   thelink = linkarray.href;

     if (thelink.indexOf("http://") === 0) {
     linkarray.target = "_blank";
     }
   }
}
window.onload = uu;

-- 
Best wishes, Osmo

Back to comp.lang.javascript | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Open all links in new window csakkoni@gmail.com - 2016-07-31 23:37 -0700
  Re: Open all links in new window Osmo Saarikumpu <osmo@weppipakki.com> - 2016-08-02 06:44 +0300
    Re: Open all links in new window "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-08-02 10:50 +0200
      Re: Open all links in new window Chandramohan Akkoni <csakkoni@gmail.com> - 2016-08-02 21:25 -0700
        Re: Open all links in new window "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-08-03 10:20 +0200
    Re: Open all links in new window Chandramohan Akkoni <csakkoni@gmail.com> - 2016-08-03 10:39 -0700
      Re: Open all links in new window "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-08-03 23:46 +0200

csiph-web