Hi. One of my company's websites is governed by an Umbraco v4.0.4.2 install - I know, old and clunky. To cut a long story short upgrading is not an option at this point.
I'm fairly on top of how Umbraco works from the back end, but I'm certainly no .NET expert, and I need to insert a snippet of JS into, I guess, the header of each page. This snippet is a mobile-detector that will redirect users to the mobile version of our site (with separate m. URL).
Firstly, I'd like to test this on one page, so I'm looking at inserting it into the header of that page and see how it fares. Secondly, assuming it works, I'd like to get that JS working so whatever page a user lands on redirects them to the mobile site if necessary.
I see there's a Scripts folder in the Settings section of Umbraco. I suppose I drop the file in here?
But of course I need to link to that file from the appropriate page, right? So I'm hoping someone can tell me how to do this, perhaps provide some nifty code example. I'm guessing it's a sort of include statement that references the filepath to the Scripts folder, but this is just guessing.
I don't know the structure of your project but dropping the file in /scripts/ sounds right to me. You can just do it on your file system. No reason to create it through Umbraco.
If you have a "/frontend" folder or "/assets" folder then just place it there.
Then in your master template you can add the script before by referencing it like
<script src="/scripts/yourscript.js"></script>
That should do the trick.
If you don't have access to the file system by only can access files etc. through Umbraco then you can of course create the file in the scripts folder in the settings section as mentioned. Referencing it would work the same way.
Since I don't know your setup I can't tell whether the approach of modifying the files in Umbraco is a good idea - If no company is working on the solution creating new builds from a version control system, then it should be fine. But if there are regular builds then the change you make through Umbraco could be overwritten.
Thanks Jan. Actually I worked out a pretty simple method; once I saw that the raw HTML for the header was embedded in the Master Page template, I inserted the JS into <script> tags in there, and as every page references that template, the mobile redirect works nicely. Probably not the neatest method, having browsers parse the script before the HTML, but to be honest this is only a temporary solution as the site won't be around much longer.
Inserting a JavaScript file
Hi. One of my company's websites is governed by an Umbraco v4.0.4.2 install - I know, old and clunky. To cut a long story short upgrading is not an option at this point.
I'm fairly on top of how Umbraco works from the back end, but I'm certainly no .NET expert, and I need to insert a snippet of JS into, I guess, the header of each page. This snippet is a mobile-detector that will redirect users to the mobile version of our site (with separate m. URL).
Firstly, I'd like to test this on one page, so I'm looking at inserting it into the header of that page and see how it fares. Secondly, assuming it works, I'd like to get that JS working so whatever page a user lands on redirects them to the mobile site if necessary.
I see there's a Scripts folder in the Settings section of Umbraco. I suppose I drop the file in here?
But of course I need to link to that file from the appropriate page, right? So I'm hoping someone can tell me how to do this, perhaps provide some nifty code example. I'm guessing it's a sort of include statement that references the filepath to the Scripts folder, but this is just guessing.
Any help would be hugely appreciated.
Hi Tom
I don't know the structure of your project but dropping the file in /scripts/ sounds right to me. You can just do it on your file system. No reason to create it through Umbraco.
If you have a "/frontend" folder or "/assets" folder then just place it there.
Then in your master template you can add the script before by referencing it like
That should do the trick.
If you don't have access to the file system by only can access files etc. through Umbraco then you can of course create the file in the scripts folder in the settings section as mentioned. Referencing it would work the same way.
Since I don't know your setup I can't tell whether the approach of modifying the files in Umbraco is a good idea - If no company is working on the solution creating new builds from a version control system, then it should be fine. But if there are regular builds then the change you make through Umbraco could be overwritten.
Hope this helps.
/Jan
Thanks Jan. Actually I worked out a pretty simple method; once I saw that the raw HTML for the header was embedded in the Master Page template, I inserted the JS into <script> tags in there, and as every page references that template, the mobile redirect works nicely. Probably not the neatest method, having browsers parse the script before the HTML, but to be honest this is only a temporary solution as the site won't be around much longer.
Cheers for your help!
Hi Tom
Happy to hear that you managed to figure it out. Sometimes it's all about being pragmatic rather than perfect :)
Cheers, Jan
is working on a reply...