none
SharePoint Anchor Tags

    Question

  • Trying to create a Wiki with Sharepoint using designer.  I enter the url in the properties window as /wiki/test.aspx#section-3 and save it.

    When I load the page on the site and click on the link it  rewrites the link for me as /wiki/test.aspx%23section-3 creating an invalid page error.

     

    How do I get Sharepoint not to mess with the URL's after they are entered directly, (a url manually entered should not be html encoded!).

     

    This is a very basic precept of hyper text markup language and should not require a workaround.  Weren't anchor tags part of the initial html spec back when no one knew what the internet was except for a few random geeks? Back when Mosaic (http://en.wikipedia.org/wiki/Mosaic_%28web_browser%29) rained supreme?

     


    Matthew Hazlett
    Clarity Computers
    http://www.devclarity.com/
    Saturday, January 01, 2011 11:31 PM

Answers

  • Here's a little workaround I have just wrote :

    <script type="text/javascript">
     setTimeout(Reload,2000);
     function Reload()
     {
      window.location.hash=self.document.location.hash.substring(1);
     }
    </script>
    

    Note 1 : Paste this code in the HTML of a "Content Editor Web Part".

    Note 2 : Page will scroll back and forth...

    Monday, February 07, 2011 3:54 PM
  • Actually, you don’t have switch to HTML view to create a inpage hyperlink.

     

    Edit your publishing page and select some text. Now click “Insert/Link/From Address”. In the pop up window just type “/” for the “Address” field. Remove “/” from the URL field and add “#Chapter1” or equivalent value to “Bookmark”.

     

    Now you will be able to create an anchor to “#Chapter1”. Just select some other text in your page. Now click “Insert/Link/From Address”. In the pop up window just type “#Chapter1” for “Address”. Save and your inpage link will work.

     

    Indeed, if you add the Content Editor Web Part and the Javascript of fcorbeil the page will scroll up and down again.  JQuery may improve on this, and we could put the Javascript inside the page layout so editors do not have to do this plumbing work J

     

    wimdg@hotmail.com

    Monday, January 30, 2012 11:24 AM

All replies

  • Very strange it seems to call this js function

    function OpenPopUpPageWithTitle(url, callback, width, height,title)
    {ULSsa6:;
    	var fn=function ()
    	{ULSsa6:;
    		var dOpt={url: url, args: null, title: title, dialogReturnValueCallback: callback, width: width, height: height};
    		var dlg=SP.UI.ModalDialog.showModalDialog(dOpt);
    	};
    	var defd;
    	try
    	{
    		defd=typeof(SP.UI.ModalDialog.showModalDialog);
    	}
    	catch (e)
    	{
    		defd="undefined"
    	}
    	EnsureScript("SP.UI.Dialog.js", defd, fn);
    }
    
    What does a link have to do with a modal dialog?
    


    Matthew Hazlett
    Clarity Computers
    http://www.devclarity.com/
    Sunday, January 02, 2011 12:16 AM
  • This problem is getting tiring:

    I had used the link maker [[test.aspx]] in the editor initally.  When I viewed the link in the designer it was a normal <A> tag. I modified the <A> tags properties in the designer but it kept changing back to the old <A> link code when I would save it. 

    So, I decided out of frustration to just delete the lines all together and manually type in the <A> link and save, this seemed to work!

     

    Now the links work right?...

    Hooray?

    Not so fast :-(

     

    The <A> links work perfactly, they load the page up perfactly.  The url is reported in the address bar perfactly.  So whats the problem?

    Aparently there is a javascript somwhere in core.js that makes the page jump to the top of the top of the document after the page loads.  So while the page loads correctly now, it dosn't matter because as soon as it finishes, it will jump to the top of the document.  Making the anchor tag useless.

     

    Maybe I should just nip it in the butt now and tell the powers that be that wordpress or joomla is a better solution for the corporate intranet, I am so fed up with this over engineered monstrosity.

     


    Matthew Hazlett
    Clarity Computers
    http://www.devclarity.com/
    Sunday, January 02, 2011 5:06 AM
  • Trying to create a Wiki with Sharepoint using designer

    Could you please let me know the detailed steps? I had create an ASPX page in SharePoint Designer 2010 and I can insert hyperlink such as http://en.wikipedia.org/wiki/Nilambur#Educational_institutions with copy and paste or the Insert->hyperlink Ribbon button. The link works well.

     

    And I can edit or create a Wiki Page in browser interface and can copy and paste link without any issue.

    Monday, January 03, 2011 1:54 AM
    Moderator
  • It only happens in Sharepoint 2010.

    1. Download 2010
    2. Create a Website / etc.
    3. Create 2 wiki pages of any name you want.
    4. Put 3 anchor tags in one file, Section 1, and make sure each tag is abut 25 lines from the previous tag (so they each look like they are n separate pages)
    5. in the second file put an A link to each section. Section 1

    Now view the file ad click on the different sections, after the page loads at the correct tag it goes to the toop of the document making the tag useless.

    Monday, January 03, 2011 1:12 PM
  • I have the same issue where anchored links are not working WITHIN SP2010 sites. I have been trying to track down a workaround for some time. Our clients are not happy that anchored links are not working on their SP 2010 publishing site pages.

    To test:

    1. I created a new 2010 publishing site collection in order to make sure this was a default SP 2010 bug and did basically the same steps as hazlema.
    2. Created a 2nd page with lots of content and created anchor tags so the page would need to scroll to the bottom.
    3. When you are on the page, and use the #bottom in the URL it works correctly.
    4. When you create a link from another page to go to Test-Page-2.aspx#bottom, it goes to the bottom at first, then the page automatically refreshes and pops back to the top of the page.

    This is a major bug, how can a simple HTML anchor tag not work properly within a SP site?

    Thanks

    Friday, January 21, 2011 12:39 AM
  • Yes, I am still waiting on my "MSDN Priority Support" on this one, its been a few weeks now.
    Matthew Hazlett
    Clarity Computers
    http://www.devclarity.com/
    Friday, January 21, 2011 1:09 AM
  • I can reproduce this, thanks for reporting and i have escalated this issue.

    BTW, i don't know this "MSDN Priority Support", part of my job is to take care of what we called "Managed case" posted by subscriber, but it is only for SharePoint 2007 currently.

    Friday, January 21, 2011 4:46 AM
    Moderator
  • Any new activity on this, been over a week.  Anyway, we moved to another solution, we could not get this to work.
    Matthew Hazlett
    Clarity Computers
    http://www.devclarity.com/
    Saturday, January 29, 2011 8:45 PM
  • Has anybody managed to find the answer for this? I  have the same issue where anchored links are not working with in SP2010 sites
    Monday, January 31, 2011 12:11 PM
  • I have the same problem here!  Any news from Microsoft?

    Monday, February 07, 2011 12:48 PM
  • Not a peep
    Matthew Hazlett
    Clarity Computers
    http://www.devclarity.com/
    Monday, February 07, 2011 1:48 PM
  • Here's a little workaround I have just wrote :

    <script type="text/javascript">
     setTimeout(Reload,2000);
     function Reload()
     {
      window.location.hash=self.document.location.hash.substring(1);
     }
    </script>
    

    Note 1 : Paste this code in the HTML of a "Content Editor Web Part".

    Note 2 : Page will scroll back and forth...

    Monday, February 07, 2011 3:54 PM
  • Does anyone have an update on this? I just encountered the bounce to the top behaviour with our SP 2010 Wiki.

    Thanks

    Wednesday, June 22, 2011 5:21 PM
  • Is there any solution to this yet, both for wikis and publishing sites?

    Monday, August 22, 2011 6:39 PM
  • The solution provided by fcorbeil above is very elegant and easy to implement. I've dropped it into my page layout for my publishing site and it works like a charm. Thanks for sharing this solution, @fcorbeil :)
    Tuesday, August 23, 2011 5:56 AM
  • Here's an improved version:

    $(function() {
    	var fn = FixRibbonAndWorkspaceDimensions;
    	FixRibbonAndWorkspaceDimensions = function() {
    		var firstCall = !g_setWidthInited;
    		fn();
    		if (firstCall) 
    			window.location.hash = self.document.location.hash.substring(1);
    	}
    });
    It's using the jQuery "ready" event functionality, but if you don't have jQuery available, you can also use document.addEventListener / document.attachEvent (be sure to check which one exists) to attach to the "load" event.

    The issue here is that FixRibbonAndWorkspaceDimensions() creates the Ribbon and does some resizing, which causes the browser to scroll to the top of the page. This snippet ensures that right after, the browser scrolls to the anchor tag. It also ensures that this is being done only on the initial load of the page as FixRibbonAndWorkspaceDimensions() is also called later (e.g. upon resize).

     


    • Edited by PSchmiedel Friday, August 26, 2011 9:50 AM formatting
    Friday, August 26, 2011 9:49 AM
  • My problem is similar but I can't use the Javascript or JQuery solutions with my Gov't Canada client since it would violate the "No Javascript" rule for external facing websites.

    Does anyone have a solution for this yet that does not require Javascript?


    We the willing, led by the unknowing, are doing the impossible for the ungrateful. We have done so much, with so little, for so long, we are now qualified to do anything, with nothing." ~ Mother Teresa ~
    Friday, September 16, 2011 6:16 PM
  • Any update on the anchor tags?

    If I try fcorbeil's script, does anyone know where in the page layout the code goes?  Do I have to change any variables or does SharePoint and the browser understand everything in there.  Sorry, I'm a hardware engineer.  I'm already way out of the boat here.

    Thanks, Mike

    Friday, October 28, 2011 5:18 AM
  • This workaround worked for me: http://sharepointsearch.com/cs/blogs/sharepointblogs/archive/2007/10/31/using-named-anchors-in-sharepoint-wiki-pages.aspx
    Friday, January 27, 2012 4:17 PM
  • Actually, you don’t have switch to HTML view to create a inpage hyperlink.

     

    Edit your publishing page and select some text. Now click “Insert/Link/From Address”. In the pop up window just type “/” for the “Address” field. Remove “/” from the URL field and add “#Chapter1” or equivalent value to “Bookmark”.

     

    Now you will be able to create an anchor to “#Chapter1”. Just select some other text in your page. Now click “Insert/Link/From Address”. In the pop up window just type “#Chapter1” for “Address”. Save and your inpage link will work.

     

    Indeed, if you add the Content Editor Web Part and the Javascript of fcorbeil the page will scroll up and down again.  JQuery may improve on this, and we could put the Javascript inside the page layout so editors do not have to do this plumbing work J

     

    wimdg@hotmail.com

    Monday, January 30, 2012 11:24 AM
  • Wim De Groote's solution worked just fine for me.  It's very similar to the one laid out by ThoughtfulTech (see link below).  The only issue I have is that in both cases, the initial text that is bookmarked ends up looking like/being a link (blue, underlined text). 

    I need the bookmark or anchor point to be invisible (think "back to the top" links).  This is easily achieved by switching to HTML view and just inserting an anchor tag as you would normally, but I am trying to avoid the HTML view for the sake of my user base who is asking for this. They need a simple solution.  Am I out of luck? 

    http://mccoard.net/ThoughtfulTech/post/2011/05/11/Creating-a-Bookmark-(anchor)-link-in-SharePoint-2010.aspx

    Thursday, February 16, 2012 3:20 AM
  • Hi all. I'm attempting to use the instructions provided via the ThoughtfulTech link.

    No problems creating the first link, or the target link (the anchor) for that matter. But when I select Link Tools and "Format" to add the bookmark, the bookmark field isn't there. I only have the URL and Description fields.

    Any idea why the bookmark field is missing? I'm running Sharepoint 2010.

    Thanks,

    Dan

    Tuesday, February 28, 2012 9:51 PM
  • I tried Wim De Groote's instructions.  My first bookmark worked, but the ones after that just bookmarked to the position of my first bookmark.  What am I doing wrong or is it a glitch?  Does the bookmark name need to not have any spaces?  So, can "Chapter1" be "Chapter 1"???

    Thanks.

    Wednesday, May 09, 2012 8:15 PM
  • The bookmark name cannot have any spaces and in some browsers is also case sensitive.
    Tuesday, May 22, 2012 3:41 AM
  • Hi all. I'm attempting to use the instructions provided via the ThoughtfulTech link.

    No problems creating the first link, or the target link (the anchor) for that matter. But when I select Link Tools and "Format" to add the bookmark, the bookmark field isn't there. I only have the URL and Description fields.

    Any idea why the bookmark field is missing? I'm running Sharepoint 2010.

    Thanks,

    Dan

    I have the same problem, the Bookmark field doesn't show up.

    Also using Sharepoint 2010.

    Ideas anyone?

    Thanks,

    dan

    Tuesday, June 12, 2012 2:26 PM
  • It also happens when you try to link to an anchor in wiki page hosted within Sharepoint365.
    Thursday, November 01, 2012 11:59 AM
  • Re: This is a major bug, how can a simple HTML anchor tag not work properly within a SP site?

    Agreed!

    Thursday, November 01, 2012 12:00 PM
  • for an anchor tag in enterprise wiki page to work, you need to create with steps in http://mccoard.net/ThoughtfulTech/post/2011/05/11/Creating-a-Bookmark-(anchor)-link-in-SharePoint-2010.aspx

    the resulting link looks like:

    Or looks like:

    Friday, November 02, 2012 7:29 AM
    Moderator
  • without the customization fcorbeil suggest, if you put the address such as http://sharepointservername/sitepath/pagename.aspx#bookmarkname into address bar, you will most probabily goto the top of page instead of the book mark, however, fcorbeil's suggestion:run the script

    window.location.hash = self.document.location.hash.substring(1)

    after sharepoint's internal javascript finished will lead you to the bookmark.

    If the end user just press enter in the address bar will also work, that is, go to the bookmark.

    But click refresh button will load the page and run SharePoint's initialization javascript again, that is, go to the top of the page.


    Friday, November 02, 2012 8:13 AM
    Moderator