Forum Moderators: coopster
In an effort to achieve W3C validation for XHTML, all ampersands have to used in the form & and this is causing strange behaviour in FireFox browser. I have a problem with the following PHP script that generates some JavaScript code.
if (empty($js_enabled)) {
if (strpos($REQUEST_URI, "?")) $REQUEST_URI .= "&js=y";
else $REQUEST_URI .= "?js=y";
$js_selflocation = $REQUEST_URI;
$js_selflocation = str_replace("&", "&", $js_selflocation);
$javascript_message =<<<JS
<script language='JavaScript' type='text/javascript'>
self.location='$js_selflocation';
</script>
JS;
The JavaScript code looks like this:
<script language='JavaScript' type='text/javascript'>
self.location='/product.php?productid=9175&js=y';
</script>
Everything works fine in IE 5 and 6, but in any version of FireFox the browser url will start off with one "&js=y" and then the URL keeps refreshing with an additional "&js=y" appended to the end of the URL. The browser gets stuck in an infinite loop.
Is there anything else I can replace the & with? I've seen some code samples using hex %26 but this is not converted to an ampersand in the URL itself. I would prefer the ampersand to display as normal.
Many thanks in advance.
--
Regards,
Asim
<script language='JavaScript' type='text/javascript'>
self.location='$js_selflocation';
</script>
Then each time the page loads the script will be executed. However, each time the php runs, it grabs the URI, meaning that you are appending it onto the end of it again...and again...and again. You have to use some kind of conditional or check to make sure that it isn't happening more than once. :)
You can get around this in two ways without changing the "&" to "&"...1. put the javascript in an external file, or
2. use... //<![CDATA[<script type="text/javascript">
//<![CDATA[
self.location='/product.php?productid=9175&js=y'
//]]>
</script>
Thanks for your help everyone.
I was thinking it was a logical error...guess not ;)