Esta es la forma mas facil que encontre de hacer que en una pagina se vea bien en los dos exploradores. Esta tecnica se basa en usar un script php para que reconozca el explorador, y hojas de estilo especificas para cada explorador.
Bueno, primero nececitamos el script php:
Este lo copiamos y lo subimos a nuestro servidor bajo el nombre de browser_detection.php.
Dsp en las paginas tenemos que poner esto en la seccion de head (suponiendo que el codigo php esta en la misma carpeta y se llama browser_detection):
Finalmente crear dos hojas de estilo:
1) Llamada ie.css para el internet explorer.
2)moz.css para el Mozilla firefox.
Y listo problema solucionado.
Un ejemplo, mi pagina: http://tuspaginas.freetzi.com .
Ahi si ven el codigo fuente, van a ver como cambia el nombre de la hoja de estilo al cual esta asociada la pagina segun el navegador que usar.
Notas:
1) La variable $a_browser_data que es un array, donde distinguimos la variable $a_browser_data[0] que es el nombre del explorador (ie para Internet explorer, moz para el mozila, no me acuerdo los valores que adopta la variable para los demas demas).
Y $a_browser_data[1] que nos da el numero de vercion del explorador.
2) Esto no es una solucion magica, ni arreglara problemas de programacion. Esta solucion se basa en que los distintos exploradores interpretan de distinta manera un mismo codigo.
Bueno, primero nececitamos el script php:
<?php
/*
Script Name: Lightweight PHP Browser Detector
Author: Harald Hope, Website: [url]http://TechPatterns.com/[/url]
Script Source URI: [url]http://TechPatterns.com/downloads/php_browser_detection.php[/url]
Version 1.1.8
Copyright (C) 28 October 2007
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
Get the full text of the GPL here: [url]http://www.gnu.org/licenses/gpl.txt[/url]
Coding conventions:
[url]http://cvs.sourceforge.net/viewcvs.py/phpbb/phpBB2/docs/codingstandards.htm?rev=1.3[/url]
*/
/*
basic function, has two tests currently, 'browser', returns shorthand for browser name,
or 'number', which returns browser number, or in mozilla's case, the rv number. You can
also use the 'full' parameter to get back both results at once, in an array.
if you need more precise browser information, get our full featured browser detection script:
[url]http://TechPatterns.com/downloads/browser_detection_php_ar.txt[/url]
Changes:
1.1.8 - fixed small error in sample code at end, msie should be ie
1.1.7 - Added default 'other' return item that will cover search spiders and other useragents
*/
function browser_detection( $which_test )
{
// initialize variables
$browser_name = '';
$browser_number = '';
// get userAgent string
$browser_user_agent = ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) ? strtolower( $_SERVER['HTTP_USER_AGENT'] ) : '';
//pack browser array
// values [0]= user agent identifier, lowercase, [1] = dom browser, [2] = shorthand for browser,
$a_browser_types[] = array('opera', true, 'op' );
$a_browser_types[] = array('msie', true, 'ie' );
$a_browser_types[] = array('konqueror', true, 'konq' );
$a_browser_types[] = array('safari', true, 'saf' );
$a_browser_types[] = array('gecko', true, 'moz' );
$a_browser_types[] = array('mozilla/4', false, 'ns4' );
# this will set a default 'unknown' value
$a_browser_types[] = array('other', false, 'other' );
$i_count = count($a_browser_types);
for ($i = 0; $i < $i_count; $i++)
{
$s_browser = $a_browser_types[$i][0];
$b_dom = $a_browser_types[$i][1];
$browser_name = $a_browser_types[$i][2];
// if the string identifier is found in the string
if (stristr($browser_user_agent, $s_browser))
{
// we are in this case actually searching for the 'rv' string, not the gecko string
// this test will fail on Galeon, since it has no rv number. You can change this to
// searching for 'gecko' if you want, that will return the release date of the browser
if ( $browser_name == 'moz' )
{
$s_browser = 'rv';
}
$browser_number = browser_version( $browser_user_agent, $s_browser );
break;
}
}
// which variable to return
if ( $which_test == 'browser' )
{
return $browser_name;
}
elseif ( $which_test == 'number' )
{
# this will be null for default other category, so make sure to test for null
return $browser_number;
}
/* this returns both values, then you only have to call the function once, and get
the information from the variable you have put it into when you called the function */
elseif ( $which_test == 'full' )
{
$a_browser_info = array( $browser_name, $browser_number );
return $a_browser_info;
}
}
// function returns browser number or gecko rv number
// this function is called by above function, no need to mess with it unless you want to add more features
function browser_version( $browser_user_agent, $search_string )
{
$string_length = 8;// this is the maximum length to search for a version number
//initialize browser number, will return '' if not found
$browser_number = '';
// which parameter is calling it determines what is returned
$start_pos = strpos( $browser_user_agent, $search_string );
// start the substring slice 1 space after the search string
$start_pos += strlen( $search_string ) + 1;
// slice out the largest piece that is numeric, going down to zero, if zero, function returns ''.
for ( $i = $string_length; $i > 0 ; $i-- )
{
// is numeric makes sure that the whole substring is a number
if ( is_numeric( substr( $browser_user_agent, $start_pos, $i ) ) )
{
$browser_number = substr( $browser_user_agent, $start_pos, $i );
break;
}
}
return $browser_number;
}
/* sample:
include('browser_detection.php');
$a_browser_data = browser_detection('full');
if ( $a_browser_data[0] !== 'ie' )
{
execute the non msie conditions
}
else // if it is msie, that is
{
if ( $a_browser_data[1] >= 5 )
{
execute the ie stuff
}
}
*/
?>Este lo copiamos y lo subimos a nuestro servidor bajo el nombre de browser_detection.php.
Dsp en las paginas tenemos que poner esto en la seccion de head (suponiendo que el codigo php esta en la misma carpeta y se llama browser_detection):
<head>
<?
include 'browser_detection.php';
$a_browser_data = browser_detection('full');
?>
<link rel="stylesheet" href="<? echo $a_browser_data[0];?>.css" type="text/css" media="all">
</head>Finalmente crear dos hojas de estilo:
1) Llamada ie.css para el internet explorer.
2)moz.css para el Mozilla firefox.
Y listo problema solucionado.
Un ejemplo, mi pagina: http://tuspaginas.freetzi.com .
Ahi si ven el codigo fuente, van a ver como cambia el nombre de la hoja de estilo al cual esta asociada la pagina segun el navegador que usar.
Notas:
1) La variable $a_browser_data que es un array, donde distinguimos la variable $a_browser_data[0] que es el nombre del explorador (ie para Internet explorer, moz para el mozila, no me acuerdo los valores que adopta la variable para los demas demas).
Y $a_browser_data[1] que nos da el numero de vercion del explorador.
2) Esto no es una solucion magica, ni arreglara problemas de programacion. Esta solucion se basa en que los distintos exploradores interpretan de distinta manera un mismo codigo.