I want to install a small mobile redirect script in the <HEAD>.
How do I do that using CMSMS?
How to add javascript to <head> tag?
Re: How to add javascript to <head> tag?
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
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?
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
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)
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>
As faglork suggest, Global Metadata can be used too (Site Admin -> Global Settings)
Re: How to add javascript to <head> tag?
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?
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?
Please post at least the error message!It gave me error message on home page.
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>
Then you're probably not using an admin account to log in to cmsms.And another thing.
I do not see site admin option when I 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?
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.
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?
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?
Please add [solved] to the subject of the first post.
Re: How to add javascript to <head> tag?
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
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