473,394 Members | 1,802 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Severe Javascript collision

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[i].getAttribute('href') != null) &&
(a[i].getAttribute('href').indexOf("://") >= 0) &&
(a[i].getAttribute('rel') == "external") &&
(a[i].getAttribute('href').indexOf("/check/referer") >= 0)){
a[i].target = '_blank';
a[i].title += ' (opens in new window)';
}
else if ((a[i].getAttribute('href') != null) &&
(a[i].getAttribute('href').indexOf("://") >= 0) &&
(a[i].getAttribute('rel') == "external")) {
a[i].title += ' (opens in new window)';
a[i].onclick = openWin;
a[i].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,toolba r=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[i].nextSibling;
while(tohide.nodeType != 1) tohide = tohide.nextSibling;
if (tohide!=next){tohide.style.display="none";}
}
}
}
function toggleNextByIdAndTag() {
var ccn="focus";
clickers=document.getElementById("toggle").getElem entsByTagName("dt");
for (i=0; i<clickers.length; i++) {
clickers[i].className+=" "+ccn;
clickers[i].onclick=function() {toggleNext(this,"dt")}
toggleNext(clickers[i],"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.
************************************************** *******************
Jan 18 '07 #1
4 2000


On Jan 18, 4:13 am, Neo Geshel <got...@geshel.orgwrote:
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

Jan 18 '07 #2
[on] wrote:
>
On Jan 18, 4:13 am, Neo Geshel <got...@geshel.orgwrote:
>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.
************************************************** *******************
Jan 18 '07 #3
Lee
Neo Geshel said:
>
[on] wrote:
>>
On Jan 18, 4:13 am, Neo Geshel <got...@geshel.orgwrote:
>>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;

--

Jan 18 '07 #4
Neo Geshel wrote:
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 <ulinto 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.
************************************************** *******************
Jan 18 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Dave | last post by:
Hi folks, I am trying to develop a routine that will handle sphere-sphere and sphere-triangle collisions and interactions. My aim is to develop a quake style collision engine where a player can...
2
by: MStepansky | last post by:
Any ideas of some of the good Javascript books that involves graphics programming: - to be able to move the images pixelwisely. - to be able to grab an image and move it around on screen (on...
4
by: Brian Basquille | last post by:
Hello all, Well, we've gotten to it: the real meaty area of my Air Hockey game.. Any help or suggestions for the following would be much appreciated. In plain terms: My paddle needs to be...
2
by: Dave Brown | last post by:
I believe I have found a severe limitation of DotNet, with respect to hosting Windows Form Controls in WebPages. It appears this is only possible when the web is configured on Port 80. Any other...
4
by: king | last post by:
I have an application which links to a 3rd-party shared library(say a) and dlopens another one(say b). And each of those 3rd party shared libraries requires another shared library respectively(say...
5
by: Cloy | last post by:
The script below loads a calendar page in an iframe and scrolls to today's date. It works just dandy on my apache/linux server, but won't do anything when I use IIS. (Nothing appears on the page...
2
by: The87Boy | last post by:
Hey I have a problem with a Javascript, which doesn't works in Firefox You can have a mouse over the 2 first pictures, but after the second picture has moved over the screen, nothing is happening...
0
by: licombo | last post by:
I am making a flash game which is similar to the classic game Asteroids. I am stuck in the final step of the game where I have to make the collision detection working before the whole game is...
1
by: May Amor | last post by:
Helu gurus!!! I have a code below about hashing method with collision resolution...My problem is how to use the collsion resolution again if the hash index though has already a value. Please kinda...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.