1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Simple Javascript Question: Changing URL on page

Discussion in 'BlackHat Lounge' started by NX_NULL, May 24, 2012.

  1. NX_NULL

    NX_NULL Regular Member Premium Member

    Joined:
    Dec 31, 2008
    Messages:
    309
    Likes Received:
    425
    I want to change the URL on my page when I receive traffic from mobile users.

    so when users from mobile device enter my page I want to change This link from :

    Code:
    <a class="checkout_link" title="Checkout" href="Desktop_checkout.php">Checkout</a>
    
    to

    Code:
    <a class="checkout_link" title="Checkout" href="Mobile_checkout.php">Checkout</a>
    

    I use this script for finding out mobile users
    Code:
    <script type="text/javascript">// <![CDATA[  
        var mobile = (/iphone|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase()));  
        if (mobile) {  
            document.location = "http://www.example.com";  
        }  
    // ]]></script>
    
    if its a mobile device it redirect to example.com, But i dont want to redirect I want to change URL on web page.



    rep and thanks will be given to any one help
    thanks
     
  2. sirthomas

    sirthomas Registered Member

    Joined:
    May 5, 2012
    Messages:
    98
    Likes Received:
    49
    Occupation:
    Local Business Marketing
    Location:
    BC, Canada
    Hey man, pretty sure this will work for you.

    Code:
    <script type="text/javascript">// <![CDATA[  
        var mobile = (/iphone|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase()));  
        if (mobile) {  
            document.write("<a class="checkout_link" title="Checkout" href="Mobile_checkout.php">Checkout</a>");  
        }else{	
    	document.write("<a class="checkout_link" title="Checkout" href="Desktop_checkout.php">Checkout</a>");	
    }
    //-->  
    // ]]></script>
    
     
    • Thanks Thanks x 1
  3. NX_NULL

    NX_NULL Regular Member Premium Member

    Joined:
    Dec 31, 2008
    Messages:
    309
    Likes Received:
    425
    hey man thanks but DW says there is a syntax error on line 12 :

    Code:
    document.write("<a class="checkout_link" title="Checkout" href="Mobile_checkout.php">Checkout</a>");
    
     
  4. sirthomas

    sirthomas Registered Member

    Joined:
    May 5, 2012
    Messages:
    98
    Likes Received:
    49
    Occupation:
    Local Business Marketing
    Location:
    BC, Canada
    Oh that's an error with the quotes I'm pretty sure.

    try this

    Code:
    <script type="text/javascript">// <=!=[=C=D=A=T=A=[  
        var mobile = (/iphone|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase()));  
        if (mobile) {  
            document.write('<a class="checkout_link" title="Checkout" href="Mobile_checkout.php">Checkout</a>');  
        }else{	
    	document.write('<a class="checkout_link" title="Checkout" href="Desktop_checkout.php">Checkout</a>');	
    }
    //-->  
    // ]=]=></script>
     
    • Thanks Thanks x 1
  5. NX_NULL

    NX_NULL Regular Member Premium Member

    Joined:
    Dec 31, 2008
    Messages:
    309
    Likes Received:
    425
    works like a charm and you are legend! :D
     
    • Thanks Thanks x 1