Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #31009
| Path | csiph.com!weretis.net!feeder4.news.weretis.net!proxad.net!feeder1-2.proxad.net!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!nzpost2.xs4all.net!not-for-mail |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Open all links in new window |
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
| References | <e1ab8ac7-2ef0-4f29-adcc-9276edc0dddf@googlegroups.com> <nnp4u4$j4t$1@dont-email.me> |
| Date | Tue, 02 Aug 2016 10:50:58 +0200 |
| Message-ID | <XnsA6586E5DF88ADeejj99@194.109.6.166> (permalink) |
| User-Agent | Xnews/2009.05.01 |
| Lines | 54 |
| NNTP-Posting-Host | 77.174.145.5 |
| X-Trace | 1470127853 dreader35.news.xs4all.nl 3975 ehannivo/77.174.145.5:60384 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.javascript:31009 |
Show key headers only | View raw
Osmo Saarikumpu <osmo@weppipakki.com> wrote on 02 Aug 2016 in
comp.lang.javascript:
> 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;
>
<script type='text/javascript'>
'use strict'
function uu() {
for (let lnk of document.links) {
lnk.target =
(/^http/.test(lnk.href))
? '_blank'
: '_self';
};
};
window.onload = uu;
</script>
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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