6

Let me preface this by saying I am working on a public facing site that is on SharePoint, we are trying to support multiple browser types with the content. So I've been asked by our Content Team to check on how SharePoint 2010 is dealing with Anchor Tags, now I did some checking around and there are some steps on how to generate them within the same page. Of course this was after discovering how they are basically unsupported and have been since MOSS 2007, this is for general content not wiki pages. On the MSDN forums this has come up a couple of times and I've followed those steps, and I have gotten them to work fine in the same page and wrote instructions for our team; although it would be nicer if these were not so convoluted. Although then the question came, can we do this for other pages? Answer was, not so fast. I did some checking and found the following behavior.

  • IE 8 - goes to the Anchor Tag on the new page, then jumps to the top. From my understanding this is due to the ribbon bar or something on the page that overrides focus
  • IE 7 - works great! This surprised me
  • IE 6 - works great! This also surprised me, but I expect lots of errors whenever I access pages
  • FireFox 3.5 - page loads and never generates a focus anywhere...not even the jump you get from IE 8

Has anyone done this, without adding code into the page, to get Anchor Tags to work across pages or am I stuck trying to code a solution or just telling the content team not to do this? Or my third alternative to them was to make a set of links at the top of the page, so Users will always see a set of anchor links in the top of the page no matter where they come from.

EDIT: One solution I have come up with, that seems to work most of the time, is using the DIV tage on certain sections of pages and using the ID to make an anchor tag so on one page I can enter

<div id="shortcut"> </div>

Then make a page link as - default.aspx#shortcut - and that seems to work much of time at least in IE9. enter code here

1
  • The answer provided right above works very well on SharePoint 2013!!. Thank you Ben and Mike !!!
    – Mavis
    Commented Jul 4, 2013 at 6:25

5 Answers 5

12

I talked with my trusted friend and branding expert, Cathy Dew, who said that Anchor Tags don't work well in SP2010. The javascript in core.js will override it most of the time. Her answer is that you either need to write code or javascript that will override the behavior from core.js or to use standard links.

1
  • This is what I thought was happening, something was overriding the options. I've seen this when logged in as an Admin and as an anonymous user (to answer djeeg's point) so I never saw this as a login issue. So with Standard Links you're pretty much giving the same option I gave, just link to the page in question and then have anchor tags within the page if that is really needed.
    – MichaelF
    Commented Apr 11, 2011 at 14:44
2

There is thread at Sharepoint's forum about the same problem with Anchor tags and a temporary solution until Microsoft decide to fix.

http://social.msdn.microsoft.com/Forums/en/sharepoint2010general/thread/f7eab808-da8a-44fd-9933-f9b992f5affc

-edit: The script at this link works beautifully, but I found the "long" 2000 millisecond delay to be jarring. I've had success with a delay as short as setTimeout(Reload,500).

I'm concerned I'm breaking protocol by editing this post, so please do advise if there is a more appropriate way for me to get this info close to the related response. -pete

1
  • I have seen that but I want to avoid a code solution if I can, thanks for the link though!
    – MichaelF
    Commented Apr 13, 2011 at 19:09
2

A little late to the party on this, but I just experienced this issue myself and came up with a fairly effective solution.

As Lori said, it seems that SharePoint's built in JS can force scroll issues that prevent anchors from working properly. The first issue you might run into is the fixed-ribbon scrolling problem that has been pretty well documented. Essentially the <body> tag never scrolls, it's the inner #s4-workspace <div> tag that does all the scrolling. If you need to fix this issue, I recommend Kyle Schaeffer's explanation.

Once you're past that, you may still have some issues. I was experiencing the "jump" that you mention because pages were trying to load at the anchor position, and then a SharePoint JS file was forcing a scroll back to the top of the page. I eventually narrowed this down to the sp.core.js script, which allows the following JavaScript code to correct the problem:

function scrollToAnchors() {
    if (window.location.hash != "") {
        window.location.hash = window.location.hash;
    }
}
ExecuteOrDelayUntilScriptLoaded(function () { scrollToAnchors(); }, "sp.core.js");

Hope this can help someone.

0
1

When you say "public facing site" I think a content site, like a publishing site with a /Pages/ library, that has anonymous access. I have only seen the behavior you describe happen when an administrator logs into the site and has the edit menu bars up, so depending on who your target audience is, it still may be viable.

In addition to what Lori says, if it is an anonymous site, you should try to suppress the extra js files.

http://www.sharepointnutsandbolts.com/2011/01/eliminating-large-js-files-to-optimize.html

1
  • That is exactly the site we have, although I am not sure about the js file supression although I imagine we will need to do that eventually.
    – MichaelF
    Commented Apr 15, 2011 at 11:51
1

One work-around might be to put your data into a SP list and then link to the list item. It's not an anchor but it is a way to send someone directly to specific content. Each list item has its own URL. (You find this out if you have worked on any customized workflow). A quick way to get an item's URL is to right click on the field that normally opens the list item and select "copy shortcut." Like wise you can click on Properties to get the URL.

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.