Enlace por Dispositivo: Web vs. Movil

  • Autor Autor NetReyes
  • Fecha de inicio Fecha de inicio
N

NetReyes

Eta
Hola,


Bueno chicos tengo este código de un reproductor fake que me pasaron, el cual solo tiene la opcion para redireccionar al hacer click a un determinado enlace.

Lo que quiero es poner dos enlaces pero que cada uno se pueda acceder dependiendo del dispositivo en este caso movil o pc.

Codigo Original
Insertar CODE, HTML o PHP:
function a(){  
          $('#modal').fadeIn(200, function(){
                $('#dialog').slideDown(300, function(){
            setTimeout("$('.hideme').hide(); $('.showme').show();", 500);
                });
            });
        };
        
        function strip(html) {
           var tmp = document.createElement("DIV");
           tmp.innerHTML = html;
           return tmp.textContent||tmp.innerText;
        };


        $(function(){
        
            var parts = window.location.search.substr(1).split("&");
            var $_GET = {};
            for (var i = 0; i < parts.length; i++) {
                var temp = parts[i].split("=");
                $_GET[decodeURIComponent(temp[0])] = decodeURIComponent(temp[1]);
            }
            
            var title = $_GET['title'];
            if (typeof(title) == 'undefined')
                title = '';
            else
                title = strip(title);
            $('#title').html(title);
                        [B]window.redirection_url = 'http://google.com.mx'[/B]
        $('#futureurl').attr('href', window.redirection_url);
            $(".button").click(function(){
                $('#playBall').fadeOut(100, function(){   
                    $('#loader').fadeIn(300);
                    setTimeout('a()', 500);
                });
            });
            $(".button").hover(
              function(){ $(this).find("img").fadeIn(50); }, 
              function(){ $(this).find("img").fadeOut(50); } 
            );
            $(".toolTip").tipTip({delay: 100, defaultPosition: 'top', maxWidth: 300});
        });

A mi parecer se puede hacer de la siguiente forma, con la etiqueta wp is mobile de la siguiente forma:

Insertar CODE, HTML o PHP:
function a(){            $('#modal').fadeIn(200, function(){
                $('#dialog').slideDown(300, function(){
            setTimeout("$('.hideme').hide(); $('.showme').show();", 500);
                });
            });
        };
        
        function strip(html) {
           var tmp = document.createElement("DIV");
           tmp.innerHTML = html;
           return tmp.textContent||tmp.innerText;
        };


        $(function(){
        
            var parts = window.location.search.substr(1).split("&");
            var $_GET = {};
            for (var i = 0; i < parts.length; i++) {
                var temp = parts[i].split("=");
                $_GET[decodeURIComponent(temp[0])] = decodeURIComponent(temp[1]);
            }
            
            var title = $_GET['title'];
            if (typeof(title) == 'undefined')
                title = '';
            else
                title = strip(title);
            $('#title').html(title);
                        [B]if (wp_is_mobile())[/B]
[B]                                                 window.redirection_url = 'http://google.com.mx'[/B]
[B]                        else[/B]
[B]                        window.redirection_url = 'http://movil.com.mx'[/B]
        $('#futureurl').attr('href', window.redirection_url);
            $(".button").click(function(){
                $('#playBall').fadeOut(100, function(){   
                    $('#loader').fadeIn(300);
                    setTimeout('a()', 500);
                });
            });
            $(".button").hover(
              function(){ $(this).find("img").fadeIn(50); }, 
              function(){ $(this).find("img").fadeOut(50); } 
            );
            $(".toolTip").tipTip({delay: 100, defaultPosition: 'top', maxWidth: 300});
        });

Como pueden ver utilizo un if para determinar el enlace, pero desafortunadame no funciona o tendré algún error
 
wp_is_mobile() es de PHP... no podes meterlo asi como asi en el code JS XD...
 
wp_is_mobile() es de PHP... no podes meterlo asi como asi en el code JS XD...

Entiendo amigo entonces alguna solucion que me recomiendes o tendre que coformarme con un solo enlace. Me gustaria para poder correr CPA en PC y Mobusi en Movil.
 
Entiendo amigo entonces alguna solucion que me recomiendes o tendre que coformarme con un solo enlace. Me gustaria para poder correr CPA en PC y Mobusi en Movil.

si ese code lo tienes dentro de un php solo coloca:
PHP:
                        <?php if (wp_is_mobile()){ ?>
                                                 window.redirection_url = 'http://google.com.mx';
                        <?php }else{ ?>
                        window.redirection_url = 'http://movil.com.mx';
                        <?php } ?>
 
Gracias pero el codigo lo tengo script

Insertar CODE, HTML o PHP:
<script language="javascript" type="text/javascript">		var isMobile = function() {
		//console.log("Navigator: " + navigator.userAgent);
		return /(iphone|ipod|ipad|android|blackberry|windows ce|palm|symbian)/i.test(navigator.userAgent);
		};
	
        function a(){
            $('#modal').fadeIn(200, function(){
                $('#dialog').slideDown(300, function(){
			setTimeout("$('.hideme').hide(); $('.showme').show();", 500);
                });
            });
        };
        
        function strip(html) {
           var tmp = document.createElement("DIV");
           tmp.innerHTML = html;
           return tmp.textContent||tmp.innerText;
        };


        $(function(){
        
            var parts = window.location.search.substr(1).split("&");
            var $_GET = {};
            for (var i = 0; i < parts.length; i++) {
                var temp = parts[i].split("=");
                $_GET[decodeURIComponent(temp[0])] = decodeURIComponent(temp[1]);
            }
            
            var title = $_GET['title'];
            if (typeof(title) == 'undefined')
                title = '';
            else
                title = strip(title);
            $('#title').html(title);
						if(isMobile())
                        window.redirection_url = 'http://google.com.mx'
						else
						window.redirection_url = 'http://perra.com.mx'
	    $('#futureurl').attr('href', window.redirection_url);
            $(".button").click(function(){
                $('#playBall').fadeOut(100, function(){   
                    $('#loader').fadeIn(300);
                    setTimeout('a()', 500);
                });
            });
            $(".button").hover(
              function(){ $(this).find("img").fadeIn(50); }, 
              function(){ $(this).find("img").fadeOut(50); } 
            );
            $(".toolTip").tipTip({delay: 100, defaultPosition: 'top', maxWidth: 300});
        });
    </script>

Me da error lo que me mencionas de todas maneras gracias.

si ese code lo tienes dentro de un php solo coloca:
PHP:
                        <?php if (wp_is_mobile()){ ?>
                                                 window.redirection_url = 'http://google.com.mx';
                        <?php }else{ ?>
                        window.redirection_url = 'http://movil.com.mx';
                        <?php } ?>
 
No me hace click, por mas que hago click no funciona el enlace como si no tuviera enlace.
dame la url por PM... porque de seguro te esta dando error... con CTRL+SHIFT+J ves la consola del navegador, vas a errores y ves que te da...
 
dame la url por PM... porque de seguro te esta dando error... con CTRL+SHIFT+J ves la consola del navegador, vas a errores y ves que te da...

Lo tengo montado en Localhost.

Este error me aparce al hacer CTRL+SHIFT+J

Failed to load resource: the server responded with a status of 404 (Not Found)
http://ads/reproductor/fullscreenHover.png
Failed to load resource: the server responded with a status of 404 (Not Found)
localhost/:96
Uncaught SyntaxError: Unexpected token <
404 Not Found
Failed to load resource: the server responded with a status of 404 (Not Found)
 
Lo tengo montado en Localhost.

Este error me aparce al hacer CTRL+SHIFT+J

Failed to load resource: the server responded with a status of 404 (Not Found)
http://ads/reproductor/fullscreenHover.png
Failed to load resource: the server responded with a status of 404 (Not Found)
localhost/:96
Uncaught SyntaxError: Unexpected token <
404 Not Found
Failed to load resource: the server responded with a status of 404 (Not Found)

faltan los ; en las url
HTML:
        if (isMobile())
            window.redirection_url = 'http://google.com.mx';
        else
            window.redirection_url = 'http://perra.com.mx';
 
faltan los ; en las url
HTML:
        if (isMobile())
            window.redirection_url = 'http://google.com.mx';
        else
            window.redirection_url = 'http://perra.com.mx';

Ya tiene las ;

Busque en google y me encontre con esto, al parecer funciona perfectamente.

Insertar CODE, HTML o PHP:
var isMobile = function() {return /(iphone|ipod|ipad|android|blackberry|windows ce|palm|symbian)/i.test(navigator.userAgent);
};

Quedando de esta forma

Insertar CODE, HTML o PHP:
function a(){            $('#modal').fadeIn(200, function(){
                $('#dialog').slideDown(300, function(){
			setTimeout("$('.hideme').hide(); $('.showme').show();", 500);
                });
            });
        };
        
        function strip(html) {
           var tmp = document.createElement("DIV");
           tmp.innerHTML = html;
           return tmp.textContent||tmp.innerText;
        };


        $(function(){
        
            var parts = window.location.search.substr(1).split("&");
            var $_GET = {};
            for (var i = 0; i < parts.length; i++) {
                var temp = parts[i].split("=");
                $_GET[decodeURIComponent(temp[0])] = decodeURIComponent(temp[1]);
            }
            
            var title = $_GET['title'];
            if (typeof(title) == 'undefined')
                title = '';
            else
                title = strip(title);
            $('#title').html(title);
			
			var isMobile = function() {
			return /(iphone|ipod|ipad|android|blackberry|windows ce|palm|symbian)/i.test(navigator.userAgent);
			};
						if(isMobile())
                        window.redirection_url = 'http://movil.com.mx';
						else
						window.redirection_url = 'http://pc.com.mx';
	    $('#futureurl').attr('href', window.redirection_url);
            $(".button").click(function(){
                $('#playBall').fadeOut(100, function(){   
                    $('#loader').fadeIn(300);
                    setTimeout('a()', 500);
                });
            });
            $(".button").hover(
              function(){ $(this).find("img").fadeIn(50); }, 
              function(){ $(this).find("img").fadeOut(50); } 
            );
            $(".toolTip").tipTip({delay: 100, defaultPosition: 'top', maxWidth: 300});
        });
 
Atrás
Arriba