Logo 
Search:

MOSS Forum

Ask Question   UnAnswered
Home » Forum » MOSS       RSS Feeds

How to add Javascript to a sharepoint master without using CEWP

  Asked By: Camille    Date: Nov 01    Category: MOSS    Views: 4385

How do I add a javascript directly to a sharepoint page without
using a CEWP? Also, what can I do to make the aspx run it server-side? I have
no permission to create web.configs.

Share: 

 

18 Answers Found

 
Answer #1    Answered By: Jack Carroll     Answered On: Nov 01

You can edit the master page in SharePoint Designer; it's usually advisable
to make a copy of the appropriate file and edit that, rather than messing
with the original.

Why are you trying to get JS to run server-side? What's your end goal here?

 
Answer #2    Answered By: Chandrabhan Agarkar     Answered On: Nov 01

Well, there are a few things. First, working with the CEWPs are clumsy; using
SPD is faster and easier with less clicks. Also, if I can make the js run
server side then I don't have to worry about my technologically impaired users
worrying about how to turn it on or off.

I have tried adding js directly to the master pages (copies are good), but I
couldn't figure out where to put it without it giving an error. Where do I
stick it?

 
Answer #3    Answered By: Lonnie Cohen     Answered On: Nov 01

I understand why you'd want to use SPD rather than a CEWP, especially since
the latter is more of a band-aid (albeit a useful one). For a master page
application, there's not much comparison.

If a user switches off JavaScript, then most of their SharePoint UI is going
to stop working. Besides, running client-side JS on the server probably
isn't going to do what you need it to do.

You should be able to stick your script block just about anywhere in the
body of the page. What kind of error are you getting?

 
Answer #4    Answered By: Anthony Rutledge     Answered On: Nov 01

I want to add these two lines, actually, then I can reuse the scripts in any
page I want. Right now I am doing this via CEWP and that works, but I'd rather
do it directly.

<link href="mycss.css" rel="stylesheet" type="text/css" />
<script src="myjs.js" type="text/javascript" ></script>

 
Answer #5    Answered By: Heena Nagori     Answered On: Nov 01

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.

 
Answer #6    Answered By: Aishwarya Karmarkar     Answered On: Nov 01

That's just it - I can't find any Head tags in Overview.aspx (a survey master).

 
Answer #7    Answered By: Janell Camacho     Answered On: Nov 01

Oh. That's not a master page. Apparently I misunderstood.

You'll need to include your script and link tags inside an asp:Content
control; these are what the master page reads to render each page's content.

 
Answer #8    Answered By: Julia Washington     Answered On: Nov 01

Probably it is me who misunderstands... Okay, I tried something like that - but
do you know what control to put it in, or do I need to create one?

 
Answer #9    Answered By: Shashwat Takle     Answered On: Nov 01

You should be able to put it inside any content placeholder, though for this
I'd recommend either PlaceHolderPageTitle or PlaceHolderAdditionalPageHead.

 
Answer #10    Answered By: Aastha Acharya     Answered On: Nov 01

That worked wonderfully! Y'all are great, and patient too!

 
Answer #11    Answered By: Glenda Roth     Answered On: Nov 01

Okay, well, that trick worked on one page, but when I try to link the
same js to a different overview.aspx, I can see that the js file is, indeed
loaded, but it doesn't run. Both overview.aspx pages have exactly the same
things in them. What gives?

 
Answer #12    Answered By: Jada Clemons     Answered On: Nov 01

How are you determining that the file is loaded? Are you checking for the
presence of certain variables or function names? What do you mean when you
say it doesn't run?

I assume that the two files -- since they are named identically -- are in
different directory locations. Did you change the path in the JS link?

 
Answer #13    Answered By: Brooke Lewis     Answered On: Nov 01

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 either
place.

I did notice, however, that if I place a single alert at the very end of the
script, on one page where the script runs it pops up twice, but on the page
where the script doesn't work, it pops up only once. I suspect some connection
between 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 the
script is kept in memory.

Maybe if I place the script contents inside a function and then call the
function at the end of the overview.aspx. Where do I put the function call? It
goes like this, right inside the aspx file: "<script>myfunction();</script> ?

 
Answer #14    Answered By: Talia Johns     Answered On: Nov 01

My mistake; I had already deleted the previous email so I didn't have the
path information available.

Did you perhaps add the script tag twice in the first page? I don't know of
any caching behavior that would cause a script to run twice in one page
load.

 
Answer #15    Answered By: Tera Callahan     Answered On: Nov 01

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 into
functions and made a function call from the asp tag "PlaceHolderBodyAreaClass".
Now both pages work fine. Thanks again for helping. Clues make all the
difference sometimes!

 
Answer #16    Answered By: Mark Davis     Answered On: Nov 01

well, that trick worked on one page, but when I try to link the
same js to a different overview.aspx, I can see that the js file is, indeed
loaded, but it doesn't run. Both overview.aspx pages have exactly the same
things in them. What gives?

 
Answer #17    Answered By: Delilah Mcpherson     Answered On: Nov 01

Probably it is me who misunderstands... Okay, I tried something like that - but
do you know what control to put it in, or do I need to create one?

 
Answer #18    Answered By: Gobinda Navalagi     Answered On: Nov 01

I want to add these two lines, actually, then I can reuse the scripts in any
page I want. Right now I am doing this via CEWP and that works, but I'd rather
do it directly.

<link href="mycss.css" rel="stylesheet" type="text/css" />
<script src="myjs.js" type="text/javascript" ></script>

 




Tagged: