Hi everyone,
I got assigned this little project when our web developer left, and I'm totally new to Javascript.
Basically we have Google Earth web pages that will show KML data for various project. Currently, they are all separate pages.
What I've been asked to do is create a template page that gets passed where the KML code resides. Which was easy enough, but the Javascript code for each page has sections that refer specifically to HTML objects.
So what I thought of doing was moving out the Google Earth Javascript code to an external file that resides with the KML code, that way the template can then load in dynamically the Javascript code for that KML data.
I found Javascript code online that will load in an external .js file, which it does.
<script src="
<script type="text/javascript">
function gup( name )
{
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec( window.location.href );
if( results == null )
return "";
else
return results[1];
}
function jsinit()
{
var gedir = gup('KMLCode');
var jssource = " + gedir + "/geJavascript.js";
var fileref=document.createElement('script');
fileref.setAttribute("type","text/javascript");
fileref.setAttribute("src", jssource);
document.getElementsByTagName("head")[0].appendChild(fileref);
}
</script>
</HEAD>
<body onload='jsinit()' id='body'>
I pass the variable in KMLCode of where the KML data and Javascript code reside, and the function JSInit will load the file in dynamically. The problem is now I get an error that Google Earth object isn't seen by the code in the external file.
Is this some type of scope issue, or is there some other issue I need to be away of when trying this type of code loading?
Thanks,
Robert
I got assigned this little project when our web developer left, and I'm totally new to Javascript.
Basically we have Google Earth web pages that will show KML data for various project. Currently, they are all separate pages.
What I've been asked to do is create a template page that gets passed where the KML code resides. Which was easy enough, but the Javascript code for each page has sections that refer specifically to HTML objects.
So what I thought of doing was moving out the Google Earth Javascript code to an external file that resides with the KML code, that way the template can then load in dynamically the Javascript code for that KML data.
I found Javascript code online that will load in an external .js file, which it does.
<script src="
<script type="text/javascript">
function gup( name )
{
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec( window.location.href );
if( results == null )
return "";
else
return results[1];
}
function jsinit()
{
var gedir = gup('KMLCode');
var jssource = " + gedir + "/geJavascript.js";
var fileref=document.createElement('script');
fileref.setAttribute("type","text/javascript");
fileref.setAttribute("src", jssource);
document.getElementsByTagName("head")[0].appendChild(fileref);
}
</script>
</HEAD>
<body onload='jsinit()' id='body'>
I pass the variable in KMLCode of where the KML data and Javascript code reside, and the function JSInit will load the file in dynamically. The problem is now I get an error that Google Earth object isn't seen by the code in the external file.
Is this some type of scope issue, or is there some other issue I need to be away of when trying this type of code loading?
Thanks,
Robert