Home > SharePoint 2010 > Fix: Publishing Hyperlink Issue

Fix: Publishing Hyperlink Issue

If you have used the Publishing Hyperlink as a list column before, you might have run into the following problem. Create a new item with a link.



The item is created properly and the link works correctly.

Now,  you don’t want to have a link for this item so you edit the item and click “Remove Link” and save the item. All is well.


Now. you change your  mind again and want to add a link back. Surprisingly,  there is no interface to add the link back again . What happened?


Taking look at the html on the form there are 2 important things to note:

  • First, is that the link still exists.
  • Second, the text for the link has been removed. Below is the html that you will find:
<A contentEditable=true href="http://www.microsoft.com" rel=sp_DialogLinkIgnore UseInlineStyle="True" 
AllowParagraphFormatting="False" AllowThemeFonts="False" AllowHtmlSourceEditing="False" AllowImageStyles="False" 
AllowFontColorsMenu="False" AllowLists="False" AllowTables="False" AllowImageFormatting="False" AllowHeadings="False" 
AllowImages="False" AllowFontsMenu="False" DisableBasicFormattingButtons="True" AllowReusableContent="False" AllowFontSizesMenu="False" 
AllowHyperlinks="True" AllowTextMarkup="False" AllowTableStyles="False" AllowInsert="False" AllowFonts="False" AllowStandardFonts="False" 
AllowImagePositioning="False" DisableCustomStyles="True" AllowStyles="False"></A>

So all is not lost, as a user, however, there’s no text to click on, you can still get to the link by tabbing through the elements on the page.  Now you will find the “Link Tools” tab available again.


Further if you move your cursor to another field such as the Title “Click to add a new hyperlink” will be available again.

Solution: By using some JavaScript added to the New Form and Edit Form, you can fix the behavior of the Remove Link button. Just hook up to the Ribbon events and then override the onclick of the Remove Link button.  The script then goes and removes the href from the anchor tag.

ExecuteOrDelayUntilScriptLoaded(function () {
    CUI.Ribbon.prototype.$L_old = CUI.Ribbon.prototype.$L;
    CUI.Ribbon.prototype.$L = function () {
        $(document).trigger('tabSelected', [this.get_selectedTabCommand()]);
}, 'cui.js');

$(document).on('tabSelected', function (e, selectedTabCommand) {
    if (selectedTabCommand == "LinkTab") {
        var removeLink = document.getElementById('Ribbon.Link.Link.Link.RemoveLink-Large');
        removeLink.onclick = (function () {
            var origOnClick = removeLink.onclick;
            return function (e) {
                var linkAddress = document.getElementById('Ribbon.Link.Link.Properties.LinkAddress');
                var linkValue = linkAddress.value;
                linkAddress.value = "";

                var linkHref = "#aspnetForm a[href$='" + linkValue + "']"
                var elemLinkHref = $(linkHref);
                elemLinkHref.attr("href", "");
                if (origOnClick != null) {

As a final note, if you want to delete the Publishing Link through the UI, without this bug happening, the URL field should be deleted instead of using the “Remove Link” button, or the script above can be added to your New Form and Edit forms.  

Categories: SharePoint 2010 Tags:
  1. No comments yet.
You must be logged in to post a comment.