1

I've a problem, because when I add first script (google widgets) to my Sharepoint Fundation at the beginning every looks like good but when I edit page in HTML source code, code is different and when I try to add second script (google widgets) my first widgets doing a double code and HTML source is strange. This happens when I add script in Contet ediotr in HTML source, I try to add this script in file .txt and indicate in Content Editor and Content Link but then script doesn't work at all.

Please help me :)

1 Answer 1

1

When you add script to a CEWP, it gets rendered when the page loads. If you then edit the web part, that script still executes, so when you save the changes you've saved the script AND what it rendered. This is one of the reasons why you should store scripts in a central repository and point the CEWP to that specific file (as opposed to putting the raw script inside the CEWP). This model also allows for greater reuse of the script on other pages of the site.

There's a number of formats you can use to link, storing your scripts in a .txt file is perfectly acceptable. Note that you still need the <script type="text/javascript"></script> blocks around the script. Save the .txt file to a document library, and point the CEWP to the relative path of the document library and text file.

Optional Additional Suggestion: In most environments I work on, publishing is turned on at the rootweb, so I'll typically create a "Scripts" document library on the rootweb and enable versioning on the library. This allows you to leverage the check-in/check-out, publishing, and approval capabilities to better control the management and maintenance of the scripts. Certainly not a requirement, but depending on the scale of what you're doing, this can add some benefits as it locates that content where much of the other "consumed" intranet content likely lives, and gives you sort of a "hub" for maintaining that. While you should never use versioning as a substitute for source control management, it does help you get a better idea of who's making changes and to what, and allows you to "preview" those changes before committing them to everyone.

5
  • Ok, but when I save script in file .txt and point in Content Editor Content link this file Sharepoint shows error "The URL is not valid for the Content Link property. Check the spelling and syntax, and then type a valid URL"
    – Andrzej
    Commented May 31, 2012 at 13:26
  • What's your URL? If you go to your library and right-click and copy address, you'll usually get some oddball additional parameters. Make sure the link you're using us just something like /sitename/Scripts/script.txt without any oddball guid references and such.
    – webdes03
    Commented May 31, 2012 at 13:44
  • Yes, but when I save (C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\script.txt) script in file .txt and indicate in Content Editor\Content link this file Sharepoint, shows error "The URL is not valid for the Content Link property. Check the spelling and syntax, and then type a valid URL". Could you check this, it's very importand for me... Thnks very much for your help, Regards
    – Andrzej
    Commented May 31, 2012 at 14:07
  • You should never manually deploy files to the 14 hive. If you have to deploy a file to the 14 hive, it should be one via a solution. If you're linking to something in layouts your URL would be http://webapp/_layouts/script.txt though to reiterate, you shouldn't be touching the 14 hive by hand.
    – webdes03
    Commented May 31, 2012 at 17:30
  • Now I understand everything and my script is working great :) Once more thank very much for your help :)
    – Andrzej
    Commented Jun 1, 2012 at 9:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.