Page 1 of 1
How to add javascript to <head> tag?
Posted: Mon Aug 12, 2013 7:35 am
by param2112
I want to install a small mobile redirect script in the <HEAD>.
How do I do that using CMSMS?
Re: How to add javascript to <head> tag?
Posted: Mon Aug 12, 2013 10:07 am
by faglork
Hi!
Depends.
If you need it on all pages:
- Global Metadata
- template(s)
- footer GCB (if you can load it at the end of the page)
If you need it on few pages/one page: the page's metadata
hth,
Alex
Re: How to add javascript to <head> tag?
Posted: Mon Aug 12, 2013 10:10 am
by velden
Just add the script to the head section in the template(s) I guess (Layout -> Templates)
When it's a script file you need to include you can upload that to for example the /uploads directory and include
Code: Select all
<__script__ type="text/javascript" src="{uploads_url}/example.js"></__script>
When you write javascript in a template or content make sure to use {literal}...javscript code here...{/literal} OR make sure all '{' are surrounded by at least one space. Else the Smarty engine will try and fail to interpret the tags.
As faglork suggest, Global Metadata can be used too (Site Admin -> Global Settings)
Re: How to add javascript to <head> tag?
Posted: Tue Aug 13, 2013 4:08 am
by param2112
I want to add the redirect script only on the home page.
This is a small mobile redirect script which will redirect mobile user to mobile website.
I went to pages > Home Page > options.
Typed in the redirect script in "Page Specific Metadata:" section. clicked apply and refreshed the home page.
It gave me error message on home page.
Here is example of redirect script.
<!--Simple Mobile Redirect-->
<__script__ type="text/javascript">
if(window.location.hash != '#r=off') {
if (screen.width <= 1023) {
document.location = "
http://m.google.com";
}
}
</__script>
And another thing.
I do not see site admin option when I log in to CMSMS.
Any ideas?
Re: How to add javascript to <head> tag?
Posted: Tue Aug 13, 2013 7:32 am
by velden
It gave me error message on home page.
Please post at least the error message!
Try:
Code: Select all
<!--Simple Mobile Redirect-->
<__script__ type="text/javascript">
{literal}
if(window.location.hash != '#r=off') {
if (screen.width <= 1023) {
document.location = "http://m.google.com";
}
}
{/literal}
</__script>
And another thing.
I do not see site admin option when I log in to CMSMS.
Then you're probably not using an admin account to log in to cmsms.
Or maybe it's an older version you did not post any
information about your system
Re: How to add javascript to <head> tag?
Posted: Tue Aug 13, 2013 11:57 am
by param2112
HI,
Thanks for your help.
<!--Simple Mobile Redirect-->
<__script__ type="text/javascript">
{literal}
if(window.location.hash != '#r=off') {
if (screen.width <= 1023) {
document.location = "http://m.google.com";
}
}
{/literal}
</__script>
The code above has worked.
It is working now.
Thanks a lot.
Re: How to add javascript to <head> tag?
Posted: Tue Aug 27, 2013 11:49 am
by psy
Yes, that's the right solution but be aware search engines, especially google may punish the site if not all pages have the mobile redirect.
Re: How to add javascript to <head> tag?
Posted: Thu Sep 12, 2013 10:39 am
by paulbaker
Please add [solved] to the subject of the first post.
Re: How to add javascript to <head> tag?
Posted: Thu Sep 12, 2013 12:35 pm
by psy
One more tip before topic is closed.
When you have a mobile domain with a different URL, eg "m.mysite.com", you need to submit a separate sitemap in the mobile XML format. See google webmasters for details. Otherwise your sites will be punished for duplicate content.
Had this happen to couple of my sites. Went from #1 to zero then back again after the mobile specific sitemap was submitted.
Hth,
Psy