How do I add a javascript directly to a sharepoint page withoutusing a CEWP? Also, what can I do to make the aspx run it server-side? I haveno permission to create web.configs.
You can edit the master page in SharePoint Designer; it's usually advisableto make a copy of the appropriate file and edit that, rather than messingwith the original.Why are you trying to get JS to run server-side? What's your end goal here?
Well, there are a few things. First, working with the CEWPs are clumsy; usingSPD is faster and easier with less clicks. Also, if I can make the js runserver side then I don't have to worry about my technologically impaired usersworrying about how to turn it on or off.I have tried adding js directly to the master pages (copies are good), but Icouldn't figure out where to put it without it giving an error. Where do Istick it?
I understand why you'd want to use SPD rather than a CEWP, especially sincethe latter is more of a band-aid (albeit a useful one). For a master pageapplication, there's not much comparison.If a user switches off JavaScript, then most of their SharePoint UI is goingto stop working. Besides, running client-side JS on the server probablyisn't going to do what you need it to do.You should be able to stick your script block just about anywhere in thebody of the page. What kind of error are you getting?
I want to add these two lines, actually, then I can reuse the scripts in anypage I want. Right now I am doing this via CEWP and that works, but I'd ratherdo it directly.<link href="mycss.css" rel="stylesheet" type="text/css" /><script src="myjs.js" type="text/javascript" ></script>
Okay; where are you adding them, and what kind of error are you getting?These could go between the <head> tags rather than the body if you like.
That's just it - I can't find any Head tags in Overview.aspx (a survey master).
Oh. That's not a master page. Apparently I misunderstood.You'll need to include your script and link tags inside an asp:Contentcontrol; these are what the master page reads to render each page's content.
Probably it is me who misunderstands... Okay, I tried something like that - butdo you know what control to put it in, or do I need to create one?
You should be able to put it inside any content placeholder, though for thisI'd recommend either PlaceHolderPageTitle or PlaceHolderAdditionalPageHead.
That worked wonderfully! Y'all are great, and patient too!
Okay, well, that trick worked on one page, but when I try to link thesame js to a different overview.aspx, I can see that the js file is, indeedloaded, but it doesn't run. Both overview.aspx pages have exactly the samethings in them. What gives?
How are you determining that the file is loaded? Are you checking for thepresence of certain variables or function names? What do you mean when yousay it doesn't run?I assume that the two files -- since they are named identically -- are indifferent directory locations. Did you change the path in the JS link?
The js is in a separate directory, and the link uses an absolute path"http://myportal.org/folder/myscript.js" so the link should be good in eitherplace.I did notice, however, that if I place a single alert at the very end of thescript, on one page where the script runs it pops up twice, but on the pagewhere the script doesn't work, it pops up only once. I suspect some connectionbetween the two pages while they are open at the same time.Why would that alert trigger twice on one page? It seems like part of thescript is kept in memory.Maybe if I place the script contents inside a function and then call thefunction at the end of the overview.aspx. Where do I put the function call? Itgoes like this, right inside the aspx file: "<script>myfunction();</script> ?
My mistake; I had already deleted the previous email so I didn't have thepath information available.Did you perhaps add the script tag twice in the first page? I don't know ofany caching behavior that would cause a script to run twice in one pageload.
I figured it out. I had a CEWP hanging around with calls to the script -which is why it was running twice on the first page. I changed the scripts intofunctions and made a function call from the asp tag "PlaceHolderBodyAreaClass". Now both pages work fine. Thanks again for helping. Clues make all thedifference sometimes!
well, that trick worked on one page, but when I try to link thesame js to a different overview.aspx, I can see that the js file is, indeedloaded, but it doesn't run. Both overview.aspx pages have exactly the samethings in them. What gives?