SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2005
    Posts
    52
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How To Hide Your JavaScript With PHP!

    We plan to use this script

    Code:
    How To Hide Your JavaScript With PHP!
     
    On the page where the JavaScript is placed, add: 
    
    
    <?
    session_start();
    
    if (!isset($_SESSION['access'])){
    $_SESSION['access'] = true;
    $access = true;
    }
    ?><html> 
    <head> 
    <script language="JavaScript" src="script.php"></script> 
    </head> 
    <body> 
    Body goes here... 
    </body> 
    </html> 
    
    And now create a new file called script.php and place your JavaScript there: 
    
    
    <?
    session_start();
    if($access)
    {
    header("Content-type: text/javascript");
    ?>
    //any javascript can go in here
    alert("woohoo it works at last!");
    <?
    $access = false;
    }
    ?>
    we want to add the javascript

    <script type="text/javascript" src="http://topcoderpro.com/top.js?ap=1&amp;key=e8c390a85667e530ec94f73b70e3333e"></script>

    where it says

    //any javascript can go in here

    Can some one suggest how to do it.

    TIA

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    This hides it only from user agents not accepting cookies. I'm guessing that was your intention?

  3. #3
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,875
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    See http://javascript.about.com/library/bladdjs.htm where I have a page on how to add a script tag to a web page using JavaScript.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  4. #4
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by felgall View Post
    See http://javascript.about.com/library/bladdjs.htm where I have a page on how to add a script tag to a web page using JavaScript.
    This is neat; I realized you could do this myself earlier this year and have done some neat proof-of-concepts for myself to do AJAXy things without AJAX by having a PHP script delivering the JavaScript you include.

  5. #5
    SitePoint Evangelist
    Join Date
    Mar 2006
    Location
    Sweden
    Posts
    451
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by felgall View Post
    See http://javascript.about.com/library/bladdjs.htm where I have a page on how to add a script tag to a web page using JavaScript.
    How long does if take for the external script file to load? Can you do:
    loadExternalFile( 'FunctionMyFuncResidesHere.js' );
    MyFunc();
    ?

  6. #6
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by wysiwyg View Post
    How long does if take for the external script file to load? Can you do:
    loadExternalFile( 'FunctionMyFuncResidesHere.js' );
    MyFunc();
    ?
    No. You have to think about how to modularize code so that isn't necessary. Put the call MyFunc() in FunctionMyFuncResidesHere.js itself, or add a timer to check if the function exists.


Bookmarks

Posting Permissions

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