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


Groups > comp.lang.javascript > #31002 > unrolled thread

Open all links in new window

Started bycsakkoni@gmail.com
First post2016-07-31 23:37 -0700
Last post2016-08-03 23:46 +0200
Articles 7 — 4 participants

Back to article view | Back to comp.lang.javascript


Contents

  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

#31002 — Open all links in new window

Fromcsakkoni@gmail.com
Date2016-07-31 23:37 -0700
SubjectOpen all links in new window
Message-ID<e1ab8ac7-2ef0-4f29-adcc-9276edc0dddf@googlegroups.com>
Dear Friends, 

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. 

Thanks in advance. 

Thanks, 
Chandramohan

[toc] | [next] | [standalone]


#31008

FromOsmo Saarikumpu <osmo@weppipakki.com>
Date2016-08-02 06:44 +0300
Message-ID<nnp4u4$j4t$1@dont-email.me>
In reply to#31002
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

[toc] | [prev] | [next] | [standalone]


#31009

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2016-08-02 10:50 +0200
Message-ID<XnsA6586E5DF88ADeejj99@194.109.6.166>
In reply to#31008
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)

[toc] | [prev] | [next] | [standalone]


#31042

FromChandramohan Akkoni <csakkoni@gmail.com>
Date2016-08-02 21:25 -0700
Message-ID<43211e71-b5cf-4916-bfa8-e5fa878c4293@googlegroups.com>
In reply to#31009
Thanks a ton.

[toc] | [prev] | [next] | [standalone]


#31046

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2016-08-03 10:20 +0200
Message-ID<XnsA65969433A1EEeejj99@194.109.6.166>
In reply to#31042
Chandramohan Akkoni <csakkoni@gmail.com> wrote on 03 Aug 2016 in 
comp.lang.javascript:

> Thanks a ton.

Maybe so, but on usenet [this NG is NOT a google group],
you should quote where you are replying on.

-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#31049

FromChandramohan Akkoni <csakkoni@gmail.com>
Date2016-08-03 10:39 -0700
Message-ID<d91d289c-189f-4240-845e-82efe81b51de@googlegroups.com>
In reply to#31008
On Tuesday, August 2, 2016 at 9:14:09 AM UTC+5:30, Osmo Saarikumpu wrote:
> 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


Dear Osmo,

Thanks a ton for the code and now the code is working fine for links but the problem is that all the pdfs and docs are not opening in a new tab.
The third party links are opening in a new tab.
I tried to do it using extensionOf(), but didnot get the results.
If you can help me out in this then it would be great for me.

Thanks,
Chandramohan

[toc] | [prev] | [next] | [standalone]


#31052

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2016-08-03 23:46 +0200
Message-ID<XnsA659F1C753E9eejj99@194.109.6.166>
In reply to#31049
Chandramohan Akkoni <csakkoni@gmail.com> wrote on 03 Aug 2016 in
comp.lang.javascript: 

> On Tuesday, August 2, 2016 at 9:14:09 AM UTC+5:30, Osmo Saarikumpu
> wrote: 
>> On 01/08/2016 09:37, csakkoni@gmail.com wrote:
>> > I have a website www.xyzabc.com (dummy site mentioned) and on the
>> > tutor 
> ials 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
> 
> 
> Dear Osmo,
> 
> Thanks a ton for the code and now the code is working fine for links but
> the problem is that all the pdfs and docs are not opening in a new tab. 
> The third party links are opening in a new tab.
> I tried to do it using extensionOf(), but didnot get the results.

Use regex, see below.

> If you can help me out in this then it would be great for me.

I showed you, thinking only external lings were to be sent to a new tab:

<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>

======================

try, if you want ONLY & ALL .pdf and .docx to have target='_blank' :

window.onload = function() {
   for (let lnk of document.links) {
      lnk.target = 
         (/.pdf$|.docx$/.test(lnk.href))
            ? '_blank'
            : '_self';
   };
};

[not tested]


-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web