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
Code:
var error = function(o) {
if(o !== '') {
alert(o);
}
};
- pub109283746374.js
Code:
// 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
Code:
<!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
__________________
Official
BinPress hand picked coder.
For anyone worried about SQL injection go have a look at my small yet powerful script
here.
Go Pledge for
Light Table, if it hit's $300,000 Python and other languages will get added.
I am 1 of 65,608 people to get a Pebble Watch :P