...

View Full Version : Resolved JS Include and usage?



DJCMBear
12-09-2010, 07:53 PM
Hi I am in the middle of building some API's for my site and have built a cernal for all API's to read but i dont want the user to add two script tags to their sites code so I was wondering how I could do this.

These are not my real files but will give you the full view of what it is I am trying to do.

- cernal.js


var error = function(o) {
if(o !== '') {
alert(o);
}
};


- pub109283746374.js


// include the cernal.js file here somehow

// Do a small function that uses the error cernal function
function ShowNotice() {
if(API_KEY !== '' && API_KEY !== undefined) {
alert('Success');
} else {
error('Sorry but you have an invalid API key.');
}
}


- http://www.userswebsite.com/demoFile.html


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>WHOISearch API Demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="http://www.mysite.com/API/pub109283746374.js"></script>
</head>
<body>
<script type="text/javascript">
//<![CDATA[
ShowNotice(); // Alerts 'Sorry but you have an invalid API key.'
//]]>
</script>
<script type="text/javascript">
//<![CDATA[
API_KEY = 'pub109283746374';
ShowNotice(); // Alerts 'Success'
//]]>
</script>
</body>
</html>


If anyone can help me it will help me so much with finishing these API's, please reply if you know how I can do this, Thank You.

DJCMBear

Shaka Zorba
12-09-2010, 08:16 PM
Sorry for the mess here. See my other reply for correct answer.

DJCMBear
12-09-2010, 08:24 PM
// include the cernal.js file here with document.write
document.write('<script type="text/javascript" src="js2.js"></script>')
// Do a small function that uses the error cernal function
function ShowNotice() {
if(API_KEY !== '' && API_KEY !== undefined) {
alert('Success');
} else {
error('Sorry but you have an invalid API key.');
}
}

Thanks for you reply but I have tried that way and it didnt work, it just wrote to the body and didnt allow me to use the functions in the functions in the cernal file.

Shaka Zorba
12-09-2010, 09:07 PM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>WHOISearch API Demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="js1.js"></script>
</head>
<body>
<script type="text/javascript">
//<![CDATA[
//API_KEY = 'pub109283746374';
ShowNotice(); // Alerts 'Sorry but you have an invalid API key.'
//]]>
</script>
</body>
</html>

js1

document.write('<s');
document.write('cript type="text/javascript" src="cernal.js"></s');
document.write('cript>');


// include the cernal.js file here somehow

// Do a small function that uses the error cernal function
function ShowNotice() {
if(typeof API_KEY != 'undefined') {
alert('Success');
} else {
setTimeout("error('Sorry but you have an invalid API key.')",1);
}
}

cernal

var error = function(o) {
if(o !== '') {
alert(o);
}
};

DrDOS
12-10-2010, 02:16 AM
document.write('<s');
document.write('cript type="text/javascript" src="cernal.js"></s');
document.write('cript>');

You don't need to do all this, just properly escape the slashes with backslashes.

document.write('script type="text/javascript src="cernal.js"><\/script>');

If it goes through two javascript processes, you will need three backslashes, etc. In a javascript process for HTML all slashes should be escaped.

DJCMBear
12-10-2010, 12:44 PM
[code]document.write('<s');
document.write('cript type="text/javascript" src="cernal.js"></s');
document.write('cript>');

You don't need to do all this, just properly escape the slashes with backslashes.

document.write('script type="text/javascript src="cernal.js"><\/script>');

If it goes through two javascript processes, you will need three backslashes, etc. In a javascript process for HTML all slashes should be escaped.


omfg thanks for the last bit of information that's the problem I was getting now I know how to stop the double loading I can now doo it to work with the cernal.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum