Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Senior Coder DJCMBear's Avatar
    Join Date
    Mar 2010
    Location
    United Kindom
    Posts
    1,173
    Thanks
    14
    Thanked 136 Times in 136 Posts

    JS Include and usage?

    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
    Last edited by DJCMBear; 12-10-2010 at 07:25 PM.
    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

  • #2
    New Coder
    Join Date
    Sep 2010
    Location
    U S of A
    Posts
    56
    Thanks
    0
    Thanked 12 Times in 12 Posts
    Sorry for the mess here. See my other reply for correct answer.
    Last edited by Shaka Zorba; 12-09-2010 at 08:21 PM.

  • #3
    Senior Coder DJCMBear's Avatar
    Join Date
    Mar 2010
    Location
    United Kindom
    Posts
    1,173
    Thanks
    14
    Thanked 136 Times in 136 Posts
    Quote Originally Posted by Shaka Zorba View Post
    // 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.
    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

  • #4
    New Coder
    Join Date
    Sep 2010
    Location
    U S of A
    Posts
    56
    Thanks
    0
    Thanked 12 Times in 12 Posts
    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="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
    Code:
    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
    Code:
    var error = function(o) {
      if(o !== '') {
        alert(o);
      }
    };
    Last edited by Shaka Zorba; 12-09-2010 at 09:07 PM.

  • #5
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,911
    Thanks
    15
    Thanked 227 Times in 227 Posts
    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.
    Last edited by DrDOS; 12-10-2010 at 03:53 PM.

  • #6
    Senior Coder DJCMBear's Avatar
    Join Date
    Mar 2010
    Location
    United Kindom
    Posts
    1,173
    Thanks
    14
    Thanked 136 Times in 136 Posts
    Quote Originally Posted by DrDOS View Post
    [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.
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •