View Full Version : RESOLVED: Javascript Conflict Error
webmaster
11-25-2007, 01:48 PM
http://blog.statcounter.com/?p=43#comment-4177
http://www.taletn.com/
I’ve just installed the extra code for SC4 beta, but it seems to mess up other JavaScript code I’m running. I’ve got a script that opens certain images in a new, custom-sized window. When I use the SC4 code, this doesn’t work anymore. I may be able to fix this at my end, but then again, the “old” StatCounter code doesn’t mess up my script.
This is the working version of the webpage with the old code. Click on the small picture of the cage on the right, and a popup will open with a larger image.
http://www.taletn.com/rats/
This is the webpage with the SC4 code added. Again Click on the small picture of the cage on the right, but this time no popup is opened.
http://www.taletn.com/rats/home_sc4.htm
- Tale
webmaster
11-25-2007, 01:48 PM
http://blog.statcounter.com/?p=43#comment-4230
I’m also having issues with the new code destroying my own javascript, as someone else has said up above somewhere.
With the new code added, my own function that normally opens a custom popup window now does nothing at all. There’s something with the second call to the javascript for the SC4 project that’s doing it.
That really cripples my page, so I can’t have the code on it at all.
ttaxi
11-26-2007, 12:21 AM
http://blog.statcounter.com/?p=43#comment-4177
http://www.taletn.com/
I’ve just installed the extra code for SC4 beta, but it seems to mess up other JavaScript code I’m running. I’ve got a script that opens certain images in a new, custom-sized window. When I use the SC4 code, this doesn’t work anymore. I may be able to fix this at my end, but then again, the “old” StatCounter code doesn’t mess up my script.
This is the working version of the webpage with the old code. Click on the small picture of the cage on the right, and a popup will open with a larger image.
http://www.taletn.com/rats/
This is the webpage with the SC4 code added. Again Click on the small picture of the cage on the right, but this time no popup is opened.
http://www.taletn.com/rats/home_sc4.htm
- Tale
******************************
<script type="text/javascript">
var features = null;
function goWin( url )
{
features = "status=no,resizable=no,scrollbars=0,menubar=no,add ressbar=0,width=620,height=675";
win = window.open(url, '', features);
}
</script>
Well I found the same problem in my mew site still in contruction, the above script stoped working, at:
http://faro.ttaxi.pt/Faro_Car_Hire_Auto-jardim-do-Algarve.html
In the price simulator link.
Can any one now how to resil this because I d' like to try the new codr on my new site.
Thanks
Baptista
ttaxi
11-26-2007, 12:24 AM
http://blog.statcounter.com/?p=43#comment-4230
I’m also having issues with the new code destroying my own javascript, as someone else has said up above somewhere.
With the new code added, my own function that normally opens a custom popup window now does nothing at all. There’s something with the second call to the javascript for the SC4 project that’s doing it.
That really cripples my page, so I can’t have the code on it at all.
I'm not using the new code too.
Because there is realy a conflit of scripts.
webado
11-26-2007, 12:34 AM
http://validator.w3.org/check?verbose=1&uri=http://faro.ttaxi.pt/Faro_Car_Hire_Auto-jardim-do-Algarve.html
In your case that may be more than just a warning, it may be an actual problem.
ttaxi
11-26-2007, 12:47 AM
http://validator.w3.org/check?verbose=1&uri=http://faro.ttaxi.pt/Faro_Car_Hire_Auto-jardim-do-Algarve.html
In your case that may be more than just a warning, it may be an actual problem.
Well I have that small problem to resolve with the validator.w3, can you help me?
I tryed to change the mine type the extention and nothing work to clear that wornnig.
Thanks for your advise.
webado
11-26-2007, 12:56 AM
I woudl change the doctype for now.
Use xhtml 1.0 strict.
Support for xhtml 1.1 isn't available in IE and you woudl have to script yoru site to serve xhtml 1.0 strict to IE with text/html and xhtml 1.1 to other browsers with xhtml/xml.
ttaxi
11-26-2007, 01:02 AM
I woudl change the doctype for now.
Use xhtml 1.0 strict.
Support for xhtml 1.1 isn't available in IE and you woudl have to script yoru site to serve xhtml 1.0 strict to IE with text/html and xhtml 1.1 to other browsers with xhtml/xml.
Thanks for your reply I gona try.
ttaxi
11-26-2007, 01:07 AM
Thanks for your reply I gona try.
http://validator.w3.org/check?uri=http%3A%2F%2Ffaro.ttaxi.pt%2F&charset=%28detect+automatically%29&doctype=Inline&group=0
Brillant I love you.
Thanks
Baptista
ttaxi
11-26-2007, 01:08 AM
I woudl change the doctype for now.
Use xhtml 1.0 strict.
Support for xhtml 1.1 isn't available in IE and you woudl have to script yoru site to serve xhtml 1.0 strict to IE with text/html and xhtml 1.1 to other browsers with xhtml/xml.
it worked now I have to change the w3 image
Thanks
Tamas Kalman
11-26-2007, 12:49 PM
Hi,
first of all thank you for testing our new beta product, SC4 with the experimental exit & download click stats. We've resolved this conflict issue - now when you add SC4 code to your existing page it will preserve your original javascript codes so the entire page will work without conflicts.
However, I've analyzed your scripts and there are two important things what I've noticed:
To achieve maximum compatibility, you always have to put the StatCounter code to the very end of your page, just before the </body> tag.
Your scripts uses a variable 'event' in every function as a parameter and there are the same 'if...' conditions with the 'event' variable at couple of places in the code. Your code will work well without the 'event' variable, it's unnecessary but makes your code incompatible. If you've removed this variable your code will be more strict & compatible.
I hope after the minor compatibility issues above resolved you can use SC4 beta without conflicts as well!
let me know if you have any questions!
Tamás Kálmán
http://blog.statcounter.com/?p=43#comment-4177
http://www.taletn.com/
I’ve just installed the extra code for SC4 beta, but it seems to mess up other JavaScript code I’m running. I’ve got a script that opens certain images in a new, custom-sized window. When I use the SC4 code, this doesn’t work anymore. I may be able to fix this at my end, but then again, the “old” StatCounter code doesn’t mess up my script.
This is the working version of the webpage with the old code. Click on the small picture of the cage on the right, and a popup will open with a larger image.
http://www.taletn.com/rats/
This is the webpage with the SC4 code added. Again Click on the small picture of the cage on the right, but this time no popup is opened.
http://www.taletn.com/rats/home_sc4.htm
- Tale
TaleTN
11-26-2007, 05:45 PM
Hi Tamás,
Thanks for your help. 8) But things aren't working as they should yet. I guess that's why it's called beta, right? :mrgreen:
I've now setup a much simpeler example of something that doesn't work with the SC4 code. Consider this line of HTML code with embedded JavaScript :
<A HREF="/rats/" onclick="alert(this.href);">Link</A>
When you click the link, you should see an alert showing you the URL, after which you're taken to the URL. But with the SC4 code you won't see the alert, and you're immediately taken to the URL.
With SC4: http://www.taletn.com/test/sc4_hack.htm
Without SC4: http://www.taletn.com/test/sc4_hack2.htm
- Tale
TaleTN
11-27-2007, 12:53 PM
I'm not sure what the problem is, but I guess something goes wrong with the capturing of onclick events on <A HREF=...> elements. I've now made a couple of more examples of possible <A HREF=...> uses, with and without (embedded) JavaScript. I've also cooked up my own little onclick event capture script, and mine works consistent in IE 7, Firefox 2.0, Mozilla 1.7 and Safari 3.0.
Without SC4 code: http://www.taletn.com/test/sc4_hack2.htm
With SC4 code: http://www.taletn.com/test/sc4_hack.htm
With my own event capture script: http://www.taletn.com/test/sc4_hack3.htm
My own event capture script: http://www.taletn.com/test/spylink.js
- Tale
webado
11-27-2007, 01:01 PM
Hi Tamás,
Thanks for your help. 8) But things aren't working as they should yet. I guess that's why it's called beta, right? :mrgreen:
I've now setup a much simpeler example of something that doesn't work with the SC4 code. Consider this line of HTML code with embedded JavaScript :
<A HREF="/rats/" onclick="alert(this.href);">Link</A>
When you click the link, you should see an alert showing you the URL, after which you're taken to the URL. But with the SC4 code you won't see the alert, and you're immediately taken to the URL.
With SC4: http://www.taletn.com/test/sc4_hack.htm
Without SC4: http://www.taletn.com/test/sc4_hack2.htm
- Tale
The SC4 script generates an onclick event on the fly, which probably means your own onclick event will get overwritten by SC4's onclick event - or viceversa.
Unfortunately I think onclick event sequences need to be controlled by some more complex techniques involving controlling waiting, all things I really don't know anything about :oops: but I've seen mentioned before.
TaleTN
11-27-2007, 01:56 PM
If that's the case, then SC4 probably can't be used on any of my websites anymore.
- Tale
webado
11-27-2007, 02:23 PM
If that's the case, then SC4 probably can't be used on any of my websites anymore.
- Tale
Probably not the beta, but when it's all done probaly yes.
Hehe, lucky for you I'm not the developer of this ;)
Tamas Kalman
11-27-2007, 03:08 PM
Dear Tale,
first of all thank you for your excellent testing pages! We've used your test pages to ensure our new improved code will work 100% compatible with your test pages using all major browsers (ff,ie,safari). We've noticed, item 5 doesn't displays an alert as it expected in the description - but the most important thing is, the two pages, hack & hack2 acts exactly the same way, it means the SC4 script doesn't affects your original code anymore. The only one difference: when you turn on SC4, you will have detailed click statistics in your StatCounter Account! :)
I hope your test will work as well as ours.
Thank you for the excellent beta testing,
Tamas Kalman
Statcounter
I'm not sure what the problem is, but I guess something goes wrong with the capturing of onclick events on <A HREF=...> elements. I've now made a couple of more examples of possible <A HREF=...> uses, with and without (embedded) JavaScript. I've also cooked up my own little onclick event capture script, and mine works consistent in IE 7, Firefox 2.0, Mozilla 1.7 and Safari 3.0.
Without SC4 code: http://www.taletn.com/test/sc4_hack2.htm
With SC4 code: http://www.taletn.com/test/sc4_hack.htm
With my own event capture script: http://www.taletn.com/test/sc4_hack3.htm
My own event capture script: http://www.taletn.com/test/spylink.js
- Tale
TaleTN
11-27-2007, 07:35 PM
first of all thank you for your excellent testing pages! We've used your test pages to ensure our new improved code will work 100% compatible with your test pages using all major browsers (ff,ie,safari).
You're welcome, and I'm glad to be of service.
We've noticed, item 5 doesn't displays an alert as it expected in the description
Ah, my mistake; the description should have read "onclick = no href, window.location = ...". Mind you, this one will probably not show up in StatCounter because it uses window.location = url instead of <A HREF="url">, but that is to be expected.
- but the most important thing is, the two pages, hack & hack2 acts exactly the same way, it means the SC4 script doesn't affects your original code anymore.
You've totally understood the purpose of my tests, excellent! :grin:
The only one difference: when you turn on SC4, you will have detailed click statistics in your StatCounter Account! :)
Indeed! At the moment I still have an extra StatCounter project to monitor my picture clicks (that's is partly why I let them open in a new window), but with the click stats there's no need for that anymore. I'll be keeping the picture popup anyway, because it works and looks great.
I hope your test will work as well as ours.
I will reinstall the code in a minute.
Thank you for the excellent beta testing,
And thank you for fixing things. :cool:
- Tale
TaleTN
11-27-2007, 10:16 PM
Alright, we're almost there, but not quite. The new SC4 code may work with my examples, but it doesn't work on my website yet. But I think I've found out why. The SC4 code has these lines in it:
var bs = s.indexOf('{');
var head = s.substr (0, bs-1);
var ps = head.indexOf('(');
var pe = head.indexOf(')');
var params = head.substring (ps+1,pe);
var plist = params.split(",");
I think the idea is that head should become something like "function largeImageLoad(ev)", so that params then becomes "ev". However, that won't work, because the 2nd parameter of substr should be a length, not an index. If you change it like this it should work:
var head = s.substr (0, bs);
I've already tested this patched SC4 code with my website, and it does work.
- Tale
Tamas Kalman
02-29-2008, 01:45 PM
Hey,
thank you for the detailed testing - again! I've tried your theory, but if I remove the '-1' from the end of the substr the only one difference what will happen is an extra 'space' will remain at the end of the string. Is it really affects any scripts? Can you send us an example where does it makes a difference? Anyway, these are only the test scripts, soon we'll convert these string operations entirely to simpler regexps (as every compatibility issues are resolved).
thank you for supporting StatCounter with quality testing,
best regards,
Tamas Kalman
Alright, we're almost there, but not quite. The new SC4 code may work with my examples, but it doesn't work on my website yet. But I think I've found out why. The SC4 code has these lines in it:
var bs = s.indexOf('{');
var head = s.substr (0, bs-1);
var ps = head.indexOf('(');
var pe = head.indexOf(')');
var params = head.substring (ps+1,pe);
var plist = params.split(",");
I think the idea is that head should become something like "function largeImageLoad(ev)", so that params then becomes "ev". However, that won't work, because the 2nd parameter of substr should be a length, not an index. If you change it like this it should work:
var head = s.substr (0, bs);
I've already tested this patched SC4 code with my website, and it does work.
- Tale
TaleTN
02-29-2008, 03:18 PM
Hi,
(It's been a a while, so I had to think back really hard, but now I remember again. :mrgreen:)
Here's an example, which you can see in action here (http://www.taletn.com/test/sc4_eg.htm):
<H1 ID="eg">SC4 Example</H1>
<SCRIPT>
function doIt(a,b,c){alert(this.tagName);}
var el = document.getElementById("eg");
el.onclick = doIt;
var s = el.onclick.toString();
var bs = s.indexOf('{');
var head = s.substr (0, bs-1);
document.write("'"+head+"'"); // Writes 'function doIt(a,b,c' intead of 'function doIt(a,b,c)'
</SCRIPT>
I use jsstrip (http://code.google.com/p/jsstrip/) to strip comments and spaces from my javascript files. Because spaces between ) and { are not required in a function declaration, jsstrip removes these, breaking your current test code. Even without jsstrip, some people might actually like to write javascript this way (perhaps because they dislike the spacebar? :p).
- Tale
Tamas Kalman
02-29-2008, 04:06 PM
Hi!
Thank you for this test-page it was super useful this time too. I've tried your page in all browsers.
First: Firefox - works well. Second: Safari: Works well. And last... IE: I see your point! I haven't expected IE's string functions differs from SF/FF! I'll fix it now, to make it IE compatible. Thanks again for the super detailed testing!
best regards,
Tamas Kalman
Hi,
(It's been a a while, so I had to think back really hard, but now I remember again. :mrgreen:)
Here's an example, which you can see in action here (http://www.taletn.com/test/sc4_eg.htm):
<H1 ID="eg">SC4 Example</H1>
<SCRIPT>
function doIt(a,b,c){alert(this.tagName);}
var el = document.getElementById("eg");
el.onclick = doIt;
var s = el.onclick.toString();
var bs = s.indexOf('{');
var head = s.substr (0, bs-1);
document.write("'"+head+"'"); // Writes 'function doIt(a,b,c' intead of 'function doIt(a,b,c)'
</SCRIPT>
I use jsstrip (http://code.google.com/p/jsstrip/) to strip comments and spaces from my javascript files. Because spaces between ) and { are not required in a function declaration, jsstrip removes these, breaking your current test code. Even without jsstrip, some people might actually like to write javascript this way (perhaps because they dislike the spacebar? :p).
- Tale
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.