views:

106

answers:

3

I'm not sure how this is Chrome specific, but it is. This is working on every other browser, including all IE* browsers etc. In fact, there's no code here that's client specific. All of this is being generated on the server. Yet after clearing Chrome's cache a million times and restarting it... the following doesn't work:

<script type="text/javascript">

// BEGIN PARAMETERS 
<?php 
    if (isset($someid) && $someid == 'foo') {
        echo "var somevar = 'foo';\n";
    } else {
        echo "var somevar = '#';\n";
    }
?>
var invisible = '#';
var text_counter = '#';
// END PARAMETERS 
</script>

On every single browser that's coming from $someid == 'foo', the var shows up properly, it comes up after viewing source as var somevar = 'foo'; Chrome consistently just shows var somevar='#';... not sure why.

I also threw this into the page that the javascript is being embedded on:

<?php
  echo "someid: {$someid}\n";
?>

and that verifies that $someid is indeed foo. yet the second else block hits, only on chrome.

UPDATE: I notice that when I right click on Chrome and hit 'Inspect Element', the CORRECT var somevar value is there. It's only in View Source that it's not set correctly. That's really odd, considering that's normal behavior if you modify the DOM after the initial HTTP GET, which isn't the case here. There isn't any XHR or funky DHTML happening. Just an HTTP GET, and the code above is processed upon that GET request.

+2  A: 

For whatever reason, $someid is either not set or not exactly equal to "foo." No one can say why that might happen in one browser but not another unless you show how and where that variable gets set. Maybe there's a space or other invisible character that still looks like "foo" when you echo it, but is actually not "foo?"

Azeem.Butt
A: 

Since I can't think of why else it would be browser specific, I'm going to assume that you're doing something in Chrome (clicking a link, submitting a form, etc) to generate a request to the page in question, and that the value of $someid depends on the request parameters somehow.

If $someid is being set directly by a request parameter, check to make sure that the value sent by Chrome is really just 'foo' and not 'foo\n', 'foo\0', 'foo ', or any other value that looks like 'foo' to us mere humans.

If you have to, break out an HTTP traffic sniffer (Fidder is a great free one for Windows) and look at what's coming out of Chrome.

Annabelle
+1  A: 

To nail down the problem, try this in HTML:

echo '<pre>"' . $someid . '"</pre>';

This will preformat the text so that you can see any characters, including whitespace. I bet there's some space after the parameter value so that it will display like

"foo "

and this is of course not equal to "foo".

If this is actually the root cause, I would suggest to optimize your request parameter processing thing. You may find the trim() function valuable.

BalusC