...

View Full Version : Possible Conflict??



F1p
09-02-2010, 08:51 PM
Heya there,

I have been trying to run two Javascripts within the same page.

The first is the Drop down menu Javascript, the second is the Picture Viewer (Click an image and it opens)


Here is a copy of the webpage (the active version has been modified to reduce confusion for users)

http://f1p.co.uk/saved%20pages/picture1.html



I have tried a noconflict, but it didn't seem to work.
As you can see, the Picture viewer works fine, but the drop down menu seems to be in conflict.

Any help please?

Philip M
09-02-2010, 08:54 PM
This topic has been covered a zillion times in this forum.

There are two reasons why two scripts can conflict and not work tigether;-

a) Duplication of function and/or variable names in the two scripts- the second will over-write the first.

b) Multiple onload statements. See:-

http://www.javascriptkit.com/javatutors/multiplejava.shtml
http://www.dyn-web.com/tutorials/combine.php

Or to resolve you can simply fire a set of functions when the page loads.

<script type="text/javascript">
window.onload = function() {
functionOne();
functionTwo();
}
</script>


"From now on, ending a sentence with a preposition is something up with which I will not put." - Sir Winston Churchill, British politician (1874 - 1965)

F1p
09-02-2010, 09:11 PM
I have no idea where to put it, that's the problem!
Would you possibly be able to do it?

Regards,

Philip M
09-02-2010, 09:18 PM
<meta name="author" content="P A Thomson">

Try P.A.Thomson. But I suggest you fix the errors in your markup first.
See http://validator.w3.org/

F1p
09-02-2010, 09:23 PM
I am P.A.Thomson..... :(


I was hoping someone could show me an implemented and working version.

F1p
09-02-2010, 09:45 PM
Oh, an example of the working Menu can be found on the site index:

http://www.f1p.co.uk/index.html

F1p
09-03-2010, 09:46 AM
This topic has been covered a zillion times in this forum.

There are two reasons why two scripts can conflict and not work together;-

a) Duplication of function and/or variable names in the two scripts- the second will over-write the first.

b) Multiple onload statements. See:-

http://www.javascriptkit.com/javatutors/multiplejava.shtml
http://www.dyn-web.com/tutorials/combine.php

Or to resolve you can simply fire a set of functions when the page loads.

<script type="text/javascript">
window.onload = function() {
functionOne();
functionTwo();
}
</script>


"From now on, ending a sentence with a preposition is something up with which I will not put." - Sir Winston Churchill, British politician (1874 - 1965)

Thanks for the help, i seem to be having problems still.

F1p
09-03-2010, 08:28 PM
[QUOTE=Philip M;989683]This topic has been covered a zillion times in this forum.

There are two reasons why two scripts can conflict and not work tigether;-

a) Duplication of function and/or variable names in the two scripts- the second will over-write the first.

b) Multiple onload statements. See:-

http://www.javascriptkit.com/javatutors/multiplejava.shtml
http://www.dyn-web.com/tutorials/combine.php

Or to resolve you can simply fire a set of functions when the page loads.

<script type="text/javascript">
window.onload = function() {
functionOne();
functionTwo();
}
</script>


What name should be entered in "functionOne and functionTwo?

Is it the location of the Javascript?
eg.



<script type="text/javascript" src="http://f1p.co.uk/pictureplayer/js/prototype.js"></script>

Function one called "prototype"?

F1p
09-03-2010, 08:40 PM
Okay,

Looking even closer!



There are two reasons why two scripts can conflict and not work together;-

a) Duplication of function and/or variable names in the two scripts- the second will over-write the first.

This seems to be the problem i think...
I have no onload tags to make them conflict.

Philip M
09-03-2010, 08:57 PM
Okay,

Looking even closer!

This seems to be the problem i think...
I have no onload tags to make them conflict.

Yes, check carefully, including variables such as for i = 0 and so on.

F1p
09-03-2010, 09:01 PM
Yes, check carefully, including variables such as for i = 0 and so on.

If i find any the same, what would be best to do?

F1p
09-03-2010, 09:08 PM
I have found:


var result

in two different Javascripts, is this a problem?

F1p
09-03-2010, 09:24 PM
Okay, i have found the same var, "var result" in two Javascripts i wish to use.


Javascript One (Original):


var result=window.location.search.match(new RegExp(headerclass+"=((\\d+)(,(\\d+))*)", "i")) //check for

"?headerclass=2,3,4" in URL
if (result!=null)
result=RegExp.$1.split(',')
return result //returns null, [index], or [index1,index2,etc], where index are the desired selected header

indices
},

Should i change "var result" to "var resultA" to stop confliction?
And should i then also change the following results to "resultA" ?



var resultA=window.location.search.match(new RegExp(headerclass+"=((\\d+)(,(\\d+))*)", "i")) //check for

"?headerclass=2,3,4" in URL
if (resultA!=null)
resultA=RegExp.$1.split(',')
return resultA //returns null, [index], or [index1,index2,etc], where index are the desired selected header

indices
},

F1p
09-03-2010, 11:07 PM
I tried this and it didn't seem to help at all...

Philip M
09-04-2010, 09:05 AM
Keep looking for duplicates! You have dealt with "result" correctly although make sure that it is not referenced elsewhere in the script.

F1p
09-04-2010, 11:46 AM
Running Firebug to http://f1p.co.uk/saved%20pages/picture1.html returns the error:


invalid array length
[Break on this error] this.length--;

(Found on "prototype.js (line 464)")

Could anyone help me with what should be done?

Sciliano
09-04-2010, 02:27 PM
P.A. Thompson:

Something to consider...

I have code that automatically creates an image gallery from a simple array. It behaves like the applications which the gray overlay effect when opening a full size image. Note the "title" attribute, which sets the value for the size of the full size images.

No HTML names or IDs are used, greatly reducing the chance for conflict with an existing document and it doesn't use any JavaScript "framework."

A demo is here, using 6 of your images.
http://www.javascript-demos.com/1/Gallery_Demo/Demo.html


You may download the complete application, in a zip file, here:
www.javascript-demos.com/download_center_lite/index_t.php?Auto_Image_Gallery.zip



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum