Javascript include and opening new windows ?

Snitz™ Forums 2000
https://forum.snitz.com/forumTopic/Posts/67528?pagenum=1
05 November 2025, 10:42

Topic


wii
Javascript include and opening new windows ?
28 July 2008, 05:33


Hi,

I have a simple javascript from an external provider, something like this:

<script language="javascript" src="http://external.com/oneinclude.js"></script>

It works just fine, but I would like all the links that this script includes to open in a new window, is there anyway I can do this editing just the include? As I don´t have access to the file itself.
Thanks a lot<

 

Replies ...


Shaggy
14 August 2008, 08:43


Is there any common factor in the URLs of the links it writes? E.G., are they all links to pages on the same site?
<
wii
20 August 2008, 09:02


Yes, they all link to the same site, I received an answer from another forum, which didn´t work for me:

http://www.sitepoint.com/forums/showthread.php?t=561642

Any help is appreciated, thanks.<
Shaggy
20 August 2008, 09:12


That would have been the first method I would have tried too. Could you mail me over a copy of the off-site script so I can test a couple of things with it?
<
wii
22 August 2008, 04:18


Mail sent !
Thanks<
Shaggy
22 August 2008, 04:23


Mail received smile
I'll try and have a look at it over lunch.
<edit>Domain not found.</edit>

<
wii
22 August 2008, 05:32


Oh, that´s right - it´s an extranet site which is not open for the public,

How can I show you this ? I can send you the HTML code, the javascript generates, if that helps.<
Shaggy
22 August 2008, 05:33


Best to send me the actual contents of the JS file, if possible.
<
wii
22 August 2008, 06:58


Mail sent !<
wii
26 August 2008, 05:55


Shaggy, any news about this ?

Thanks<
wii
11 September 2008, 03:07


Anyone ?<
Shaggy
11 September 2008, 04:18


Oop; sorry, buddy, forgot all about this somehow blush I'll have another look this afternoon.
<
Shaggy
12 September 2008, 04:10


No joy as yet, man.
<
wii
23 September 2008, 03:45


I know it´s not easy, but there must be a way to do this.<
Shaggy
23 September 2008, 04:08


It should be easy; maybe it's the brain fail I've been suffering from the past few months that's throwing me off the scent - gonna give it 1 more try over lunch this afternoon.
<
wii
01 October 2008, 07:22


How was lunch ? bigsmiletongue<
HuwR
01 October 2008, 12:38


obviously an extended one bigsmile<
AnonJr
01 October 2008, 13:48


I guess Shaggy's "out to lunch"? tongue (couldn't help it)

If his work schedule has been anything like mine has been lately I can certainly understand.<
wii
06 October 2008, 03:08


If I could just get the **** code to work posted by someone at Sitepoint, I would be happy.<
Carefree
06 October 2008, 07:31


Originally posted by wii
Yes, they all link to the same site, I received an answer from another forum, which didn´t work for me:

http://www.sitepoint.com/forums/showthread.php?t=561642

Any help is appreciated, thanks.

That php site is plagued by the same scrollcode/code issue we had here: it incorrectly strings all code in one line if you copy/paste. These will copy/paste correctly. The 1st part of the code from PMW57 should read as below:
Code:
<div id="externalProvider">
<script language="javascript"
src="http://external.com/oneinclude.js"></script>
</div>
The 2nd part of the code from PMW57 should read as below:
Code:
document.getElementById('externalProvider').onclick = function (evt) {
evt = evt || window.event;
targ = evt.target || evt.srcElement;
// this = the div element
// targ = the clicked on element
if (targ.nodeName !== 'A') {
return;
}
window.open(targ.href);
}

See if that fixes it.<
wii
06 October 2008, 08:46


Yeah, I´ve tried that - I think my problem is that I don´t know where and how to insert the code for the 2nd part, the first part is obvious to include the javascript code in my HTML, but how do I include the 2nd code ?
I have tried to include it like this in the HTML page, but that doesn´t work:

<script language="javascript" type="text/javascript">

document.getElementById('externalProvider').onclick = function (evt) {
evt = evt || window.event;
targ = evt.target || evt.srcElement;
// this = the div element
// targ = the clicked on element
if (targ.nodeName !== 'A') {
return;
}
window.open(targ.href);
}
</script><
Carefree
06 October 2008, 11:55


Anywhere within the < body> < /body> should work. Some claim that you get the best performance by putting scripts immediately before the close of the body. I haven't noticed any appreciable improvement one way or the other, so I cannot attest to the legitimacy of that.
<
wii
07 October 2008, 03:38


Yeah, done that - doesn´t work.
I´m gonna give up on this one...<
© 2000-2021 Snitz™ Communications