• Resolved photocurio

    (@photocurio)


    I’ve got an odd case where all browsers on Windows machines render a site one way, and all mac browsers render the site differently.

    I want to use this plugin, and query_vars, to load an extra stylesheet if the platform is Windows. Can someone tell me how this should be phrased? I’ve tried the following, but it does not work. My code editor says there is an error in the 4th line.

    <?php
    if(get_query_var('platform')){
    	$platform = get_query_var('platform');
    	if $platform = 'windows' { ?>
    <link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo( 'stylesheet_directory' ); ?>/pc.css" />
    	<?php }
     } ?>

    https://www.ads-software.com/extend/plugins/mobile-client-detection-plugin/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter photocurio

    (@photocurio)

    I fixed the error in the above code, I think. It needs parentheses:
    if ($platform = 'windows')
    But the query still doesn’t work. When the page is viewed on a Windows machine, it does not load the pc.css stylesheet.

    Plugin Author syslogic

    (@syslogic)

    switch($platform){case:"windows":/* your code */break;}
    looks fine to me, maybe check your editors’ encoding once.
    DOS/Linux have different line ending, matters with server-side code.

    I’d assume that the CSS styles are just unevenly supported – or not layered out in the expected way. Would just preg_match() only for Safari browsers and show them an additional CSS file (only a very simple pattern for 1 single browser, to be able to use it on a live site, considering each pageload); just use FireBug or Chrome DOM inspector to see what’s going on.

    Think there’s some conditional functions as well, adding Safari like that might be most compatible/portable … e.g. is_Safari()… to be added into the theme’s functions.php

    Sure one could also think Windows needs to be fixed – I’d just use FireFox or Chrome on any platform as reference for a browser which supports CCS3 and then fix “the rest”.

    Besides I wouldn’t trust a code-editor’s syntax highlight too much (it’s just meant to help), rather matters what PHP interpreter, DOM inspector and JS debugger says… https://www.php.net/manual/en/function.error-reporting.php

    Plugin Author syslogic

    (@syslogic)

    function is_AppleWebkit(){
       if(preg_match("/\sapplewebkit\/(\d+\.\d+)/", strtolower($_SERVER["HTTP_USER_AGENT"]), $a)){
          return true;
       }
       else {
          return false;}
    }

    https://www.useragentstring.com/pages/Safari

    ^ something like that into functions.php (it’s an untested pattern) to be available in the theme’s header.php – just would need to have mobile Safari considered as well. I’d even add it to the repository, if you could confirm it catches the browser; just don’t have any Mac have, the last one was a Motorola 68k Emu ??

    Plugin Author syslogic

    (@syslogic)

    it’s just recommend to check for single browsers with simple regex-pattern, because everything else might delay the page-load event by some milliseconds. i mean, the more simple the pattern are – the quicker the match is made by the regex-engine; and the load process continues a little sooner.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Using query_vars to detect windows’ is closed to new replies.