Simple Javascript Question: Changing URL on page

NX_NULL

Banned - Multiple Rules Violations
Joined
Dec 31, 2008
Messages
717
Reaction score
930
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
 
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>
 
Hey man, pretty sure this will work for you.

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>

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>");
 
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>
 
Back
Top