Jump to content

i want to add javascript code in cms page


fatheeym

Recommended Posts

i want to add this code in cms page

<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>

<script>
        $(document).ready(function (){
         if(navigator.userAgent.toLowerCase().indexOf("android") > -1){
             window.location.href = 'http://play.google.com/store/apps/details?id=com.truecaller&hl=en';
         }
         if(navigator.userAgent.toLowerCase().indexOf("iphone") > -1){
             window.location.href = 'http://itunes.apple.com/lb/app/truecaller-caller-id-number/id448142450?mt=8';
         }
        });
</script>

and this code can't be in the main js file because it will redirect user to the app for his/her smartphone OS

thank you 

Link to comment
Share on other sites

you can add there condition to check what cms page is viewed

based on Daresh suggestion, you can use something like:

if ($('body').hasClass('cms-3')) {
}

each cms page has own unique class in <body> tag. 

3 in the example above is an ID of terms of conditions page.

 

you can change it to work only on selected page, just replace "3" with ID of target cms page.

  • Like 2
Link to comment
Share on other sites

if ($('body').hasClass('cms-3')) {

<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
 
<script>
$(document).ready(function (){
if(navigator.userAgent.toLowerCase().indexOf("android") > -1){
window.location.href = 'http://play.google.com/store/apps/details?id=com.truecaller&hl=en';
}
if(navigator.userAgent.toLowerCase().indexOf("iphone") > -1){
window.location.href = 'http://itunes.apple.com/lb/app/truecaller-caller-id-number/id448142450?mt=8';
}
});
</script>

}

so the code will be like this

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...