how to call javascript function from php ?

Discussion in 'JavaScript' started by mmjanjust, Oct 14, 2010.

  1. #1
    hi all,
    i want to using navigator.appVersion to get user's os ,
    and return the value to php in order to save the value to db ,
    so how to call navigator.appVersion from php , and return the value to php ??
     
    mmjanjust, Oct 14, 2010 IP
  2. vaneesv

    vaneesv Well-Known Member

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    106
    #2
    I think calling javascript function from php is not possible
     
    vaneesv, Oct 15, 2010 IP
  3. hdewantara

    hdewantara Well-Known Member

    Messages:
    540
    Likes Received:
    47
    Best Answers:
    25
    Trophy Points:
    155
    #3
    Doesn't PHP have its own function to do this task,
    i.e: get_browser()? But if you prefer javascript's navigator.Appversion,
    then perhaps you have to write a javascript function which reports
    back to server using Ajax technique. The Ajax should call PHP to save
    navigator.Appversion result into DB
     
    hdewantara, Oct 15, 2010 IP
  4. jocurileus

    jocurileus Peon

    Messages:
    53
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    This is php code!
    
    $browser = get_browser(null, true);
    echo $browser['browser']." ".$browser['version'];
    
    Code (php):
    Should echo "Yourbrowsersname version", eg "Firefox 5.0"
     
    jocurileus, Oct 15, 2010 IP
  5. pro-php-developer

    pro-php-developer Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    One is same as given above.or you could use eval() in JS,and few other more
     
    pro-php-developer, Oct 16, 2010 IP
  6. jek8519

    jek8519 Peon

    Messages:
    41
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    There are different scripts.
    Php is working on server side generating web page html-code (including javascript references in it). Then web page lives it's own life and javascript is working on client side where php means nothing.

    The only thing you can do is insert js calling in "onload" attribute of <body>.
     
    jek8519, Oct 22, 2010 IP
  7. AnoxiA

    AnoxiA Peon

    Messages:
    27
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7

    this is heavily counts on your browsercap.ini you set!
    many times it wont work,
    and once agian, search for:
    PHP BrowserCap
    @ SourceForge
    it should find it, a great solution!

    also, as jek8519 said,
    PHP is a server-side lang, which means the code renders at the server then returns the HTML-CSS-JS to your browser to render!

    you can always use a <a> tag fot executing js eg
    <a href="javascript:myfunc();" >blab</a>
    Code (markup):
     
    AnoxiA, Oct 23, 2010 IP
  8. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #8
    something like (at the top of your page):
    
    <script type="text/javascript">
    window.location.href = window.location.href + "?browser=" + navigator.appVersion;
    </script> 
    
    Code (markup):
    This will reload the page, with the browser in the querystring. You can then access this easily from php. An alternative is to use ajax or even an iframe or image to save the data:
    
    <img id="savebrowser" style="display: none" />
    <script type="text/javascript">
    document.getElementById("savebrowser").src = "savebrowser.php?browser=" + navigator.appVersion;
    </script>
    
    Code (markup):
     
    camjohnson95, Oct 25, 2010 IP