Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

In Sharepoint (2010) wiki pages it is easy enough to add a hyperlink, but how can one add a hyperlink anchor without editing the messy html?

You can see here that, although I've got a link and typed in an anchor into the bookmark field, it complains. I can save it, and it seems to remember what I put there, but when I try to use it by linking to the anchor, it doesn't jump (that is, <a href="#anchor1">jump</a> doesn't work).

I've looked over this tutorial, but it doesn't seem to work.

enter image description here

But the blurb there in the screenshot says, "You can make hyperlinks that jump directly to a bookmarked location" - okay, fine, well, how do I do that?

share|improve this question
add comment

5 Answers

up vote 1 down vote accepted

I have managed to make this work by combining the information here and here.

  • To enable the bookmark functionality you need to get an admin to enable SharePoint Server Publishing Infrastructure feature on the site collection level and then the SharePoint Server Publishing feature must be activated on the site level.

    1. Start by selecting the text that you want the link to point to.
      Link selection

    2. Insert a new link From Address
      Insert new hyperlink

    3. Paste the current page address in the Address field Paste destination address

    4. Add your bookmark name (without the hash) Add bookmark name

    5. Select the text that should point to your bookmark and insert a new link From Address Insert new hyperlink

    6. Type the name of the destination bookmark (don't forget the hash) Add name of destination bookmark

    7. Save the page

share|improve this answer
    
Your answer creates a hyperlink TO a destination. The question I asked was how to add the anchor - how do you add the DESTINATION in the first place? –  BGM Mar 3 at 15:24
    
The anchor is added in step 4 –  MoonSire Mar 4 at 6:14
    
Ah, you got me on that, sorry! It does seem to work - I can't believe it. I spent hours on that. The trick was creating the hyperlink anchor with the page address as the hyperlink destination. This is a better solution than mine, so I'm marking yours correct. Thank you! –  BGM Mar 4 at 15:08
add comment

Ah, here is a way.

The idea is that the user using the wiki editor will create a new hyperlink and use a special token to denote an anchor. In my example, the token is /__

I chose that because the hyperlink has to start with something that the editor would accept - and it will accept a /. Also, because it is very rare to see a hyperlink with /__ anywhere in the string.

Thus, the user would use the regular wiki richtext editor, then use the "insert hyperlink" button, and specify a hyperlink like this:

/__myanchor

The function

This needs to be added in a Content Editor or in the master page somewhere. The function will look for that pattern and add a hyperlink name based on the specified link that was given, and then remove the false hyperlink (where the optional parameter specifies a # which causes it to be a hyperlink to that same page, which means it doesn't cause any navigation), or, if the parameter is specified, it will supply that url as a default.

function WikiLinks(defaulthyperlink){
    if(!defaulthyperlink)
          defaulthyperlink = "#";
    $(".ms-wikicontent a").each(function(){
        var thishref = $(this).attr('href');    
        if(thishref.indexOf('/__') >= 0){
            thisanchor = String(thishref).substring(3, String(thishref).length);            
            $(this).attr('name', thisanchor );
            $(this).attr('href',defaulthyperlink);
        }
    }); 
}

If you decide to use a different token, make sure the change the length in the thisanchor substring search.

[update]

The catch to this is that you must call the function after the UI is loaded. This means that the function works (like a charm) only within a single page. You can't use it to link to an anchor in another page because the linkage fires before the script gets to add the anchor name.

share|improve this answer
    
Did this work for you? –  TempaC Jul 19 '13 at 7:40
1  
Yes, it works as long as you load the function after the UI is loaded, but it only works within a single page. You can't link to anchours in other pages. I'll explain in my answer. –  BGM Jul 19 '13 at 13:43
add comment

The wiki editor could make this easier :-)

This method works for me...

  1. Highlight a word in the header where you want to insert an anchor; then copy the word
  2. Press Ctrl-K. In my instance default text appears in the address field "/site/site/", click OK to accept the default
  3. You'll notice that a Link Tools ribbon appears. Paste the anchor name into the anchor field
  4. Go to your link text and highlight it; then insert a link "from address." Add "#" and paste again.

I have no idea if this will work in your case. Step 2 is weird. But it's the only way that I can invoke the "link tools" ribbon. Too bad this isn't part of the Link options from the get go.

[[EDIT: I didn't notice this before but SharePoint inserts the anchor/id AND a href link and there's nothing you can do about it except edit the HTML so my answer isn't much of a solution, unfortuntately.]]

share|improve this answer
1  
Sorry so slow to respond... No, editing the html is not the answer. I tried your method, but the "bookmark" field is grayed out and it doesn't save. –  BGM Jul 17 '13 at 4:13
add comment

The only way to do it is use an anchor tag in the code:

<a name="MyAnchor"></a>

Then add a hyperlink to the page the anchor is on, but include #MyAnchor:

http://mysite.com/wiki/page.aspx#MyAnchor

If there's a better way, let me know.

share|improve this answer
1  
Yeah, I don't want to do it in the code. I've folks whose mind would leave their body if I asked them to edit code. Besides, the code-editor is quite unwieldy. –  BGM Jul 17 '13 at 4:17
    
Okay, there is a better way... :) –  BGM Jul 17 '13 at 22:26
add comment

This is a rather old post, but hopefully this will help someone else in the future.

In regards to intra-page hyperlinking in SharePoint 2010, I found it is easiest to do through MS Word with book marks, and hyperlinks.

Highlight destination, click Insert> Bookmark. Label Bookmark and hit add. Then highlight your source (what you want to click on to take you to your destination bookmark), click insert> hyperlink> Place in this document > Select your bookmark.

When you copy and paste this into SharePoint 2010, it will work, or at least has for me.

share|improve this answer
2  
I think you've missed the point - the point was to achieve the inter-page hyperlinking inside a sharepoint WIKI PAGE - not a Word document. The Wiki Page has issues. –  BGM Jan 31 at 22:23
    
@TimothyHerlihy Does this action work on a Wiki-page too, and not only a content editor non wiki page/web part? –  Benny Skogberg Feb 1 at 2:28
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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