Jump to content
fatheeym

i want to add javascript code in cms page

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 

Share this post


Link to post
Share on other sites

Try to add additional condition to it, something like:

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

...

}

Share this post


Link to post
Share on other sites

/themes/your-theme/js/cms.js

this file is included only to cms pages.

Share this post


Link to post
Share on other sites

thank yoy for your replies

but thats mean if any customer go to any cms page he will be redirect to app store or play store even if this page was the terms or delivery page

i want this code to be only on one cms page not all pages

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

thank you for your replay but i'm  not a programmer please type the full code :D

Share this post


Link to post
Share on other sites

code above is full code.

you have to identify the ID of CMS page for which you want to enable the script

and replace "cms-3" with id of your cms page for example "cms-1"

  • Like 1

Share this post


Link to post
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

Share this post


Link to post
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...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More