Results 1 to 10 of 10
  1. #1
    Join Date
    Jan 2006
    Posts
    115
    Plugin Contributions
    0

    Default Javascript Detection in user's browser

    Hi,

    Is there any way can detect if browser's Javascript is on?
    I knwo the <noscript>,
    but I would like to have code in
    includes/modules/sidebox/YOUR_Template/newsidebox.php
    like following

    if ($javascript_on) {
    require_once (DIR_WS_CLASSES .'newsidebox_generator.php');
    ....
    $right_arrow = false;
    $title_link = false;
    require($template->get_template_dir($column_box_default, DIR_WS_TEMPLATE, $current_page_base,'common'.) . '/' . $column_box_default);
    }

    Thanks
    Eric

  2. #2
    Join Date
    Oct 2006
    Posts
    5,477
    Plugin Contributions
    11

    Default Re: Javascript Detection in user's browser

    You can have your javascript call a php file, this file will set the session $_SESSION['js_on'] = true; for example. Then in your php, check if $_SESSION['js_on'] is true.
    I no longer provide installation support on forum for all my modules. However, if there are real bugs with the modules please feel free to contact me

  3. #3
    Join Date
    Jan 2006
    Posts
    115
    Plugin Contributions
    0

    Default Re: Javascript Detection in user's browser

    Quote Originally Posted by yellow1912 View Post
    You can have your javascript call a php file, this file will set the session $_SESSION['js_on'] = true; for example. Then in your php, check if $_SESSION['js_on'] is true.
    Hi,

    Sorry, I tried for 3 days, I don't even know where to start.
    Would you give me a simple sample?

    What I want to do is:
    I got two sidebox(category boxes), if javascript==on call one of the box
    else call the other one.

    I did find a sample from the internet, but I don't know where it should be in zencart.
    <?php
    session_start();
    if (!isset($_SESSION['js_on']) || $_SESSION['js_on'] == false)
    {
    if (isset($_POST['jstest'])) {
    $_SESSION['js_on'] = true;
    } else {
    echo '<form name="jsform" id="form1" method="post" action="" style="display:none">';
    echo '<input name="jstest" type="hidden" value="js_on" />';
    echo '<script type="text/javascript" language="javascript">';
    echo 'document.jsform.submit();';
    echo '</script>';
    echo '</form>';
    $_SESSION['js_on'] = false;
    }
    }
    // rest of script goes here....
    // etc
    echo "javascript is ".($_SESSION['js_on'] ? "on":"off")."<br>";
    echo 'normal script here';
    ?>

    Thanks
    Eric

  4. #4
    Join Date
    Feb 2006
    Location
    Tampa Bay, Florida
    Posts
    10,520
    Plugin Contributions
    127

    Default Re: Javascript Detection in user's browser

    That Software Guy. My Store: Zen Cart Support
    Available for hire - See my ad in Services
    Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
    Do you benefit from Zen Cart? Then please support the project.

  5. #5
    Join Date
    Jan 2006
    Posts
    115
    Plugin Contributions
    0

    Default Re: Javascript Detection in user's browser

    Thanks.
    But I don't want to put the message on the screen.
    I guess the session idea is good, but I don't know how to do it.

    Eric

  6. #6
    Join Date
    Oct 2006
    Posts
    5,477
    Plugin Contributions
    11

    Default Re: Javascript Detection in user's browser

    It's pretty simple, but not straight forward, I will give you some hints since I know how it can work but I dont have any testing code done:

    You will need to use AJAX here, the idea is to call a php file onload using js, this php file will set the session, and in the main page you will check if this session is set or not.

    This snippet here can give you some idea:
    http://www.webtoolkit.info/ajax-file-upload.html

    Please note that in this snippet the upload.php file in called when the form is submitted, in your case you will want to call the file when the page is loaded, so you will init it in body onload.

    Now in your php file, assuming you put it in store root dir:
    1. you have to include application top first to init session
    require_once('includes/application_top.php');
    2. The set the session
    $_SESSION['js_on'] = true;

    And that's it.
    I no longer provide installation support on forum for all my modules. However, if there are real bugs with the modules please feel free to contact me

  7. #7
    Join Date
    Oct 2006
    Posts
    5,477
    Plugin Contributions
    11

    Default Re: Javascript Detection in user's browser

    1 more thing: if you want to check the javascript setting EACH time the page is loaded, the remember to set $_SESSION['js_on'] = false; after you check it.
    I no longer provide installation support on forum for all my modules. However, if there are real bugs with the modules please feel free to contact me

  8. #8
    Join Date
    Oct 2006
    Posts
    5,477
    Plugin Contributions
    11

    Default Re: Javascript Detection in user's browser

    Okie, I did a test and find out it's a bit simpler that I thought, still have some small problems tho:

    in your includes/templates/your_template/jscript
    Create a new file called jscript_check.php with the following content:
    PHP Code:
    <script type="text/javascript"
             
    src="jscript_check.php">
    </script> 
    Now in the store root folder (the folder that contains "includes" folder)
    Create a new file called jscript_check.php with the following content:
    <?php
    require('includes/application_top.php');
    $_SESSION['js_on'] = true;
    ?>


    That's it. However, for some reason, the sessions is only set on the 2nd load of the page. So say if the customer lands on the site, and then visit another page or refresh the page --> the session is set.
    It can be something to do with the require('includes/application_top.php'); since it executes lots of things and slows down the whole script.
    One thing you can do is: you have to go in and see how zen session is init, and you have to only take the part that init the session.

    I tried in the js file:
    PHP Code:
    <script type="text/javascript"
             src="jscript_check.php?zenid=<?php echo zen_session_id(); ?>">
    </script>
    and then in the php file:
    PHP Code:
    <?php
        session_name
    ('zenid');
        if (isset(
    $_GET['zenid'])) 
              
    session_id($_GET['zenid']);
          
          
    session_start();
        
    $_SESSION['js_on'] = true;
    ?>

    The zenid is passed in correctly but the session is not. So yeah, let me know if you get it working.

    Regards.
    I no longer provide installation support on forum for all my modules. However, if there are real bugs with the modules please feel free to contact me

  9. #9
    Join Date
    Jan 2006
    Posts
    115
    Plugin Contributions
    0

    Default Re: Javascript Detection in user's browser

    Quote Originally Posted by yellow1912 View Post
    Okie, I did a test and find out it's a bit simpler that I thought, still have some small problems tho:

    in your includes/templates/your_template/jscript
    Create a new file called jscript_check.php with the following content:
    PHP Code:
    <script type="text/javascript"
             
    src="jscript_check.php">
    </script> 
    Now in the store root folder (the folder that contains "includes" folder)
    Create a new file called jscript_check.php with the following content:
    <?php
    require('includes/application_top.php');
    $_SESSION['js_on'] = true;
    ?>


    That's it. However, for some reason, the sessions is only set on the 2nd load of the page. So say if the customer lands on the site, and then visit another page or refresh the page --> the session is set.
    It can be something to do with the require('includes/application_top.php'); since it executes lots of things and slows down the whole script.
    One thing you can do is: you have to go in and see how zen session is init, and you have to only take the part that init the session.

    I tried in the js file:
    PHP Code:
    <script type="text/javascript"
             src="jscript_check.php?zenid=<?php echo zen_session_id(); ?>">
    </script>
    and then in the php file:
    PHP Code:
    <?php
        session_name
    ('zenid');
        if (isset(
    $_GET['zenid'])) 
              
    session_id($_GET['zenid']);
          
          
    session_start();
        
    $_SESSION['js_on'] = true;
    ?>

    The zenid is passed in correctly but the session is not. So yeah, let me know if you get it working.

    Regards.
    Hi,

    Thank you so much for the code.
    But I don't understand the "AJAX file upload" part, would you please give me some more information.

    Thanks

  10. #10
    Join Date
    Jan 2006
    Posts
    115
    Plugin Contributions
    0

    Default Re: Javascript Detection in user's browser

    Quote Originally Posted by ericpeng View Post
    Hi,

    Thank you so much for the code.
    But I don't understand the "AJAX file upload" part, would you please give me some more information.

    Thanks
    I guess my question is how can I init it in body onload ?

    Thanks

 

 

Similar Threads

  1. How to save user and password in browser?
    By scaleachiocciola in forum General Questions
    Replies: 3
    Last Post: 18 Apr 2012, 03:07 PM
  2. Cross Browser Styles / Browser Detection?
    By SutroSonics in forum Templates, Stylesheets, Page Layout
    Replies: 4
    Last Post: 8 Nov 2006, 09:28 PM
  3. Login detection code
    By fbzencart in forum General Questions
    Replies: 4
    Last Post: 11 Oct 2006, 03:53 PM

Posting Permissions

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