Hi I'm trying to do some kind of Include For JavaScript.
Take a Look:
function include(path, file, type)
{
var head = document.getElementsByTagName('head')[0].firstChild;
var result = false;
for(head; head != null; head = head.nextSibling)
{
if((type == "script")||(type == "css"))
{
if((head.src)||(head.href))
{
if(head.src)
{
if(head.src.indexOf(file) > -1)
{
result = true;
break;
}
}
else if(head.href)
{
if(head.href.indexOf(file) > -1)
{
result = true;
break;
}
}
}
}
}
if(!result)
{
if(type == "script")
{
var script = document.createElement('script');
script.setAttribute('type', 'text/javascript');
script.setAttribute('src' , path + file);
document.getElementsByTagName('head')[0].appendChild(script);
}
else
{
var link = document.createElement('link');
link.setAttribute('rel', 'stylesheet');
link.setAttribute('type', 'text/css');
link.setAttribute('href', path + file);
document.getElementsByTagName('head')[0].appendChild(link);
}
}
}
But On My HTML
<html>
<head>
<script type="text/javascript" src="include.js"></script>
<script type="text/javascript">
include("alert1.js");
include("", "alert1.js", "script");
include("", "alert1.js", "script");
include("", "alert1.js", "script");
include("", "alert1.js", "script");
include("", "alert1.js", "script");
include("", "alert1.js", "script");
include("", "alert2.js", "script");
document.write(teste1);
document.write(teste2);
</script>
</head>
<body>
</body>
</html>
And The Files, alert1.js and alert2.js
alert1.js
var teste1 = "alert1";
alert2.js
var teste2 = "alert2";
..
The problem is that looks like the files alert1 and alert2 are not loaded, but if you put on the files alert("teste1") and alert("teste2") the script will work.
I don't know if I Came Across, but it is not much dificult.
I d like to do some kind of it.
Thank You
Leonardo
Take a Look:
function include(path, file, type)
{
var head = document.getElementsByTagName('head')[0].firstChild;
var result = false;
for(head; head != null; head = head.nextSibling)
{
if((type == "script")||(type == "css"))
{
if((head.src)||(head.href))
{
if(head.src)
{
if(head.src.indexOf(file) > -1)
{
result = true;
break;
}
}
else if(head.href)
{
if(head.href.indexOf(file) > -1)
{
result = true;
break;
}
}
}
}
}
if(!result)
{
if(type == "script")
{
var script = document.createElement('script');
script.setAttribute('type', 'text/javascript');
script.setAttribute('src' , path + file);
document.getElementsByTagName('head')[0].appendChild(script);
}
else
{
var link = document.createElement('link');
link.setAttribute('rel', 'stylesheet');
link.setAttribute('type', 'text/css');
link.setAttribute('href', path + file);
document.getElementsByTagName('head')[0].appendChild(link);
}
}
}
But On My HTML
<html>
<head>
<script type="text/javascript" src="include.js"></script>
<script type="text/javascript">
include("alert1.js");
include("", "alert1.js", "script");
include("", "alert1.js", "script");
include("", "alert1.js", "script");
include("", "alert1.js", "script");
include("", "alert1.js", "script");
include("", "alert1.js", "script");
include("", "alert2.js", "script");
document.write(teste1);
document.write(teste2);
</script>
</head>
<body>
</body>
</html>
And The Files, alert1.js and alert2.js
alert1.js
var teste1 = "alert1";
alert2.js
var teste2 = "alert2";
..
The problem is that looks like the files alert1 and alert2 are not loaded, but if you put on the files alert("teste1") and alert("teste2") the script will work.
I don't know if I Came Across, but it is not much dificult.
I d like to do some kind of it.
Thank You
Leonardo