IdentifiantMot de passe
Loading...
Mot de passe oubli� ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les r�ponses en temps r�el, voter pour les messages, poser vos propres questions et recevoir la newsletter

JavaScript Discussion :

Fonction de reconnaissance de browser ne marche pas


Sujet :

JavaScript

Vue hybride

Message pr�c�dent Message pr�c�dent   Message suivant Message suivant
  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Avril 2007
    Messages
    37
    D�tails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2007
    Messages : 37
    Par d�faut Fonction de reconnaissance de browser ne marche pas
    Bonjour � tous,

    Voici la fonction que j'ai cr�� et qui me permet temporairement de d�tecter la version du navigateur du visiteur et de le rediriger vers la page de t�l�chargement de la version plus r�cente de son browser (c'est temporaire le temps que je fasse un css compatible pour les vieux browser) :

    function detectversion() {

    var NomNav = navigator.appName;
    var VersNav = navigator.appVersion;

    if (NomNav == "Microsoft Internet Explorer" && VersNav < 7) {
    GoTo = "navweb.php";
    }
    if (NomNav == "Opera" && VersNav < 9){
    GoTo = "navweb.php";
    }
    if (NomNav == "Firefox" && VersNav < 2){
    GoTo = "navweb.php";
    }
    if (NomNav == "Safari" && VersNav < 3){
    GoTo = "navweb.php";
    }

    window.location.href = GoTo;
    }
    La partie dans ma page index.php :

    <SCRIPT LANGUAGE="Javascript" SRC="fonctionjs.js"> function detectversion(); </SCRIPT>
    Or je n'arrive pas � savoir pourquoi mais quand je teste avec un IE6 d'acc�der � mon site web je ne suis pas redirig�, j'ai tout simplement la page index normale et avec des effets css r�duit donc logiquement.

    Pourriez vous me corriger si possible ?

    Merci d'avance !

  2. #2
    Nouveau candidat au Club
    Profil pro
    Inscrit en
    Septembre 2008
    Messages
    2
    D�tails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2008
    Messages : 2
    Par d�faut D�tection du navigateur
    Pour plus de pr�cision utilise le param�tre navigator.userAgent pour la recherche du navigateur !

    Code : S�lectionner tout - Visualiser dans une fen�tre � part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
     
    function detectversion() {
     
    var VersNav = navigator.appVersion;
     
    if(navigator.userAgent.indexOf("MSIE") != -1 && VersNav < 7){
        GoTo = "/navweb.php";
    } else if(navigator.userAgent.indexOf("Firefox") != -1 && VersNav < 2){
        GoTo = "/navweb.php";
    } else if(navigator.userAgent.indexOf("Opera") != -1 && VersNav < 9){
        GoTo = "/navweb.php";
    } else if(navigator.userAgent.indexOf("Safari") != -1 && VersNav < 3){
        GoTo = "/navweb.php";
    } else if(navigator.userAgent.indexOf("Netscape") != -1){
        GoTo = "/navweb.php";
    } else {
        // Autre
        GoTo = "/navweb.php";
    }
     
    window.location.href = GoTo;
    }
    Fais appel � ta fonction dans une autre balise SCRIPT que celle avec laquelle tu appelles ton fichier "fonctionjs.js".

    Code : S�lectionner tout - Visualiser dans une fen�tre � part
    1
    2
    3
    4
    5
     
    <SCRIPT LANGUAGE="Javascript" SRC="fonctionjs.js"></SCRIPT>
    <SCRIPT LANGUAGE="Javascript"><!-- 
    detectversion(); 
    // --></SCRIPT>
    Et voil� !!!

  3. #3
    Nouveau candidat au Club
    Profil pro
    Inscrit en
    Septembre 2008
    Messages
    2
    D�tails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2008
    Messages : 2
    Par d�faut Oupsss !!!
    Desfois on parle trop vite !!!

    Le param�tre navigator.appVersion donne un chaine et non une version en clair donc tu ne peux pas utiliser ce param�tre de cette fa�ons !

    Voici un bout de code trouver sur un autre site qui pourra t'aider :

    Code : S�lectionner tout - Visualiser dans une fen�tre � part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
     
    var BrowserDetect = {
    	init: function () {
    		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
    		this.version = this.searchVersion(navigator.userAgent)
    			|| this.searchVersion(navigator.appVersion)
    			|| "an unknown version";
    		this.OS = this.searchString(this.dataOS) || "an unknown OS";
    	},
    	searchString: function (data) {
    		for (var i=0;i<data.length;i++)	{
    			var dataString = data[i].string;
    			var dataProp = data[i].prop;
    			this.versionSearchString = data[i].versionSearch || data[i].identity;
    			if (dataString) {
    				if (dataString.indexOf(data[i].subString) != -1)
    					return data[i].identity;
    			}
    			else if (dataProp)
    				return data[i].identity;
    		}
    	},
    	searchVersion: function (dataString) {
    		var index = dataString.indexOf(this.versionSearchString);
    		if (index == -1) return;
    		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
    	},
    	dataBrowser: [
    		{ 	string: navigator.userAgent,
    			subString: "OmniWeb",
    			versionSearch: "OmniWeb/",
    			identity: "OmniWeb"
    		},
    		{
    			string: navigator.vendor,
    			subString: "Apple",
    			identity: "Safari"
    		},
    		{
    			prop: window.opera,
    			identity: "Opera"
    		},
    		{
    			string: navigator.vendor,
    			subString: "iCab",
    			identity: "iCab"
    		},
    		{
    			string: navigator.vendor,
    			subString: "KDE",
    			identity: "Konqueror"
    		},
    		{
    			string: navigator.userAgent,
    			subString: "Firefox",
    			identity: "Firefox"
    		},
    		{
    			string: navigator.vendor,
    			subString: "Camino",
    			identity: "Camino"
    		},
    		{		// for newer Netscapes (6+)
    			string: navigator.userAgent,
    			subString: "Netscape",
    			identity: "Netscape"
    		},
    		{
    			string: navigator.userAgent,
    			subString: "MSIE",
    			identity: "Explorer",
    			versionSearch: "MSIE"
    		},
    		{
    			string: navigator.userAgent,
    			subString: "Gecko",
    			identity: "Mozilla",
    			versionSearch: "rv"
    		},
    		{ 		// for older Netscapes (4-)
    			string: navigator.userAgent,
    			subString: "Mozilla",
    			identity: "Netscape",
    			versionSearch: "Mozilla"
    		}
    	],
    	dataOS : [
    		{
    			string: navigator.platform,
    			subString: "Win",
    			identity: "Windows"
    		},
    		{
    			string: navigator.platform,
    			subString: "Mac",
    			identity: "Mac"
    		},
    		{
    			string: navigator.platform,
    			subString: "Linux",
    			identity: "Linux"
    		}
    	]
     
    };
    BrowserDetect.init();
    Voici la source : http://www.quirksmode.org/js/detect.html

    Avec ta fonction �a donnerais :
    Code : S�lectionner tout - Visualiser dans une fen�tre � part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
     
    function detectversion() {
     
    if(BrowserDetect.browser == 'Explorer' && BrowserDetect.version < 7){
        GoTo = "http://www.tonsiteweb.com/navweb.php";
    } else if(BrowserDetect.browser == 'Firefox' && BrowserDetect.version < 2){
        GoTo = "http://www.tonsiteweb.com/navweb.php";
    } else if(BrowserDetect.browser == 'Opera' && BrowserDetect.version < 9){
        GoTo = "http://www.tonsiteweb.com/navweb.php";
    } else if(BrowserDetect.browser == 'Safari' && BrowserDetect.version < 3){
        GoTo = "http://www.tonsiteweb.com/navweb.php";
    } else {
        // Autre
        GoTo = "http://www.tonsiteweb.com/autre.php";
    }
     
    window.location.href = GoTo;
    }
    Voil� !

  4. #4
    R�dacteur/Mod�rateur

    Avatar de SpaceFrog
    Homme Profil pro
    D�veloppeur Web Php Mysql Html Javascript CSS Apache - Int�grateur - Bidouilleur SharePoint
    Inscrit en
    Mars 2002
    Messages
    39 659
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    �ge : 75
    Localisation : Royaume-Uni

    Informations professionnelles :
    Activit� : D�veloppeur Web Php Mysql Html Javascript CSS Apache - Int�grateur - Bidouilleur SharePoint
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2002
    Messages : 39 659
    Billets dans le blog
    1
    Par d�faut
    fais une recherche sur google avec ultimate browser sniffer ...
    Ma page Developpez - Mon Blog Developpez
    Pr�sident du CCMPTP (Comit� Contre le Mot "Probl�me" dans les Titres de Posts)
    Deux r�gles du succ�s: 1) Ne communiquez jamais � quelqu'un tout votre savoir...
    Votre post est r�solu ? Alors n'oubliez pas le Tag

    Venez sur le Chat de D�veloppez !

  5. #5
    Membre averti
    Profil pro
    Inscrit en
    Avril 2007
    Messages
    37
    D�tails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2007
    Messages : 37
    Par d�faut
    Merci BQ911 ! Je regarde cela ce midi pour voir si �a marche!

    Par contre je ne comprend pas pourquoi le fait que j'appelle ma fonction dans la m�me balise que je d�clare mon fichier js peut interf�rer dans le bon fonctionnement de celle ci ??

    Par contre avec ta deuxieme m�thode donc qui devrait �tre la bonne, il faut aussi que je copie toute la fonction browserdetect dans le js, �a m'enchante pas des masses, c'est lourd quand m�me pour une simple d�tection.
    Pourquoi ne pas utiliser navigator.useragent alors?

    Merci

  6. #6
    Membre averti
    Profil pro
    Inscrit en
    Avril 2007
    Messages
    37
    D�tails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2007
    Messages : 37
    Par d�faut
    Ca marche ! Impec pour moi, merci !!

+ R�pondre � la discussion
Cette discussion est r�solue.

Discussions similaires

  1. Fonction rtrim dans un foreach ne marche pas
    Par xnadyx dans le forum Langage
    R�ponses: 5
    Dernier message: 14/08/2014, 12h09
  2. R�ponses: 1
    Dernier message: 24/06/2014, 11h42
  3. R�ponses: 9
    Dernier message: 20/09/2008, 21h56
  4. Fonction Date() sous Acces 2003 ne marche pas.
    Par fanico11 dans le forum Requ�tes et SQL.
    R�ponses: 11
    Dernier message: 27/05/2008, 18h22
  5. Fonction sql Round(N,n) ne marche pas ?
    Par quanou dans le forum Access
    R�ponses: 1
    Dernier message: 15/05/2008, 09h07

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo