Severe Javascript collision

N

Neo Geshel

I am experiencing a collision between two scripts, but I cannot find
where it is. I am hoping that someone here can help me.

I have two external JS files that I call into each web page. One
provides me with a standards-compliant way of creating pop-up windows by
simply adding a rel="external" to each anchor. The other allows me to
have toggled definition lists.

When the popupwin.js file is by itself, all anchors with rel="external"
and an external address (http://...) work just fine, spawning windows
just as required. When I add the toggle.js file, it works properly, but
causes the popupwin.js file to stop working completely. Why? How can I
correct this?

Below are the two files:

<!--start popupwin.js -->
function popWin(){
if (!document.getElementsByTagName) return;
var a = document.getElementsByTagName('a');
var agt = navigator.userAgent.toLowerCase();
var is_ie = ((agt.indexOf("msie") >= 0) && (agt.indexOf("opera") == -1));
for (var i=0; i<a.length; i++){
if ((is_ie) && (a.getAttribute('href') != null) &&
(a.getAttribute('href').indexOf("://") >= 0) &&
(a.getAttribute('rel') == "external") &&
(a.getAttribute('href').indexOf("/check/referer") >= 0)){
a.target = '_blank';
a.title += ' (opens in new window)';
}
else if ((a.getAttribute('href') != null) &&
(a.getAttribute('href').indexOf("://") >= 0) &&
(a.getAttribute('rel') == "external")) {
a.title += ' (opens in new window)';
a.onclick = openWin;
a.onkeypress = openWin;
}
}
}
function openWin() {
var url = this.href;
var target = '_blank';
var options = 'top=' + (screen.availHeight/2-250) + ',left=' +
(screen.availWidth/2-400) +
',outerwidth=800,outerheight=500,menubar=no,toolbar=no,locationbar=no,personalbar=no,directories=no,statusbar=no,scrollbars=yes,resizable=yes';
window.open(url,target,options);
return false;
}
window.onload = popWin;
<!--end popupwin.js-->




<!--start toggle.js-->
function toggleNext(el,tname,first) {
var next=el.nextSibling;
var tags=el.parentNode.getElementsByTagName(tname);
while(next.nodeType != 1) next = next.nextSibling;
next.style.display=((next.style.display=="none") ? "block" : "none");
if (first!=1){
for (i=0; i<tags.length; i++) {
var tohide=tags.nextSibling;
while(tohide.nodeType != 1) tohide = tohide.nextSibling;
if (tohide!=next){tohide.style.display="none";}
}
}
}
function toggleNextByIdAndTag() {
var ccn="focus";
clickers=document.getElementById("toggle").getElementsByTagName("dt");
for (i=0; i<clickers.length; i++) {
clickers.className+=" "+ccn;
clickers.onclick=function() {toggleNext(this,"dt")}
toggleNext(clickers,"dt",1);
}
}
window.onload=toggleNextByIdAndTag;
<!--end toggle.js-->


Thanks for any help.
....Geshel
--
*********************************************************************
My e-mail address is an automatically monitored spam honeypot. Do not
send e-mail there unless you wish to be reported as a spammer. Please
send any e-mail to my first name at my last name dot org.
*********************************************************************
 
O

[on]

I am experiencing a collision between two scripts, but I cannot find
where it is. I am hoping that someone here can help me.

I have two external JS files that I call into each web page. One
provides me with a standards-compliant way of creating pop-up windows by
simply adding a rel="external" to each anchor. The other allows me to
have toggled definition lists.

When the popupwin.js file is by itself, all anchors with rel="external"
and an external address (http://...) work just fine, spawning windows
just as required. When I add the toggle.js file, it works properly, but
causes the popupwin.js file to stop working completely. Why? How can I
correct this?

Below are the two files:

<!--start popupwin.js -->
[snip]

window.onload = popWin;
<!--end popupwin.js-->

<!--start toggle.js-->
[snip]

window.onload=toggleNextByIdAndTag;
<!--end toggle.js-->

The last "window.onload = function" overwrites the first one.

Here's a TIP someone made that might help you.
http://blog.firetree.net/2005/07/17/javascript-onload/
Thanks for any help.
...Geshel

I tried anyways, hope the link helps.

// Switchable
 
N

Neo Geshel

I am experiencing a collision between two scripts, but I cannot find
where it is. I am hoping that someone here can help me.

I have two external JS files that I call into each web page. One
provides me with a standards-compliant way of creating pop-up windows by
simply adding a rel="external" to each anchor. The other allows me to
have toggled definition lists.

When the popupwin.js file is by itself, all anchors with rel="external"
and an external address (http://...) work just fine, spawning windows
just as required. When I add the toggle.js file, it works properly, but
causes the popupwin.js file to stop working completely. Why? How can I
correct this?

Below are the two files:

<!--start popupwin.js -->
[snip]

window.onload = popWin;
<!--end popupwin.js-->

<!--start toggle.js-->
[snip]

window.onload=toggleNextByIdAndTag;
<!--end toggle.js-->

The last "window.onload = function" overwrites the first one.

Here's a TIP someone made that might help you.
http://blog.firetree.net/2005/07/17/javascript-onload/

Actually, when I implemented the code suggested by the link, none of my
scripts work. I still believe that I am experiencing a JS collision somehow.

I am far from an expert on Javascript. Can a script in one external JS
file affect a script in another external JS file? Can JS scripts in
different external files communicate with each other?

TIA
....Geshel
--
*********************************************************************
My e-mail address is an automatically monitored spam honeypot. Do not
send e-mail there unless you wish to be reported as a spammer. Please
send e-mail to my first name at my last name dot org.
*********************************************************************
 
L

Lee

Neo Geshel said:
I am experiencing a collision between two scripts, but I cannot find
where it is. I am hoping that someone here can help me.

I have two external JS files that I call into each web page. One
provides me with a standards-compliant way of creating pop-up windows by
simply adding a rel="external" to each anchor. The other allows me to
have toggled definition lists.

When the popupwin.js file is by itself, all anchors with rel="external"
and an external address (http://...) work just fine, spawning windows
just as required. When I add the toggle.js file, it works properly, but
causes the popupwin.js file to stop working completely. Why? How can I
correct this?

Below are the two files:

<!--start popupwin.js -->
[snip]

window.onload = popWin;
<!--end popupwin.js-->

<!--start toggle.js-->
[snip]

window.onload=toggleNextByIdAndTag;
<!--end toggle.js-->

The last "window.onload = function" overwrites the first one.

Here's a TIP someone made that might help you.
http://blog.firetree.net/2005/07/17/javascript-onload/

Actually, when I implemented the code suggested by the link, none of my
scripts work. I still believe that I am experiencing a JS collision somehow.

I am far from an expert on Javascript. Can a script in one external JS
file affect a script in another external JS file? Can JS scripts in
different external files communicate with each other?


The scripts are not executing in different external files.
They are each loaded into the current page environment and then executed.

They're very clearly colliding in the definition of the
window.onload function. One solution is to define a new
function that calls both of those functions and invoke that
new function as your onload event handler:

function invokeBoth() {
popWin();
toggleNextByIdAndTag();
}
window.onload=invokeBoth;



--
 
N

Neo Geshel

Neo said:
Actually, when I implemented the code suggested by the link, none of my
scripts work. I still believe that I am experiencing a JS collision
somehow.

I am far from an expert on Javascript. Can a script in one external JS
file affect a script in another external JS file? Can JS scripts in
different external files communicate with each other?

Actually, I have solved the issue. Unfortunately, the linked suggestion
wasn’t it... it simply didn’t work for me.

What I did was look at a third script, one that has never failed me...
nav.js, my script for turning a <ul> into an expandable navigational
menu (a very slick thing once combined with a generous dollop of CSS!).
This script used the following method to launch itself:

function WindowOnLoad(obj, evType, fn){
if (obj.addEventListener){
obj.addEventListener(evType, fn, false);
return true;
} else if (obj.attachEvent){
var r = obj.attachEvent("on"+evType, fn);
return r;
} else {
return false;
}
}
WindowOnLoad(window, "load", makeTreesC);

So what I did was extract that function into a separate JS file (just to
keep things clean!) and used that same method of calling it across all
three scripts. And upon uploading and page refresh... voilà, all my
scripts worked. YAY!

One final wrinkle, though. Even though they all work, IE7 throws an
error... there is the yellow warning symbol and “Error on page†on the
left side of the status bar, when double-clicked it brings up the
console that provides an “Object doesn’t support this property or
method†error. All the scripts still work, though, so I don’t know what
is up. =( Hell, IE doesn’t even tell me which script is the culprit!

Thanks for all the help, as the suggested article actually sent me on
the right path.
...Geshel
--
*********************************************************************
My e-mail address is an automatically monitored spam honeypot. Do not
send e-mail there unless you wish to be reported as a spammer. Please
send e-mail to my first name at my last name dot org.
*********************************************************************
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top