I would like to change the Title URL field of a content editor based on javascript.

I currently have a content editor that displays an Iframe of a document library.

How can I make the title of the content editor change to a hyperlink using javascript?

Using the below picture, I would like to click on "project documents" and have it take me to the document library shown.

enter image description here

  • Nate has already provided you with a solution, and it actually fits what you wanted to do. I would like to point out that I would avoid trying to change something that is formally outside the webpart - in a sense this seems like a violation of the single responsibility patterns. I was wondering - wouldn't be simpler to just move the "link" inside the content editor web part and hide the web part chrome so that the original title isn't displayed? – BlueSoul Jul 28 '16 at 18:16
  • honestly i really like this idea, going to try it out:) – Sabien Ambrose Jul 28 '16 at 18:47
  • Glad I could help. I won't probably post this a reply because the original question was pretty specific, but if this alternate solution works for you, it will be probably be better than trying to change the out-of-box title at runtime. – BlueSoul Jul 28 '16 at 18:58
  • edit: I got this extra link to work, but I am not sure how to hide the title and make the new link sit in the correct spot – Sabien Ambrose Jul 28 '16 at 19:02
  • to hide the tittle, you have to go to the web part Properties, then under Appearence set the option Chrome Type to None. As for the position of the replacer link, you will have to work it out via CSS, based on you requirement – BlueSoul Jul 30 '16 at 8:58

I accomplished this using jQuery:

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
        var linkText = $(".ms-webpart-titleText").text();
        $(".ms-webpart-titleText").html("<a href='InsertURL'>" +linkText+ "</a>");

You can place the script in a script editor above the content editor webpart.

| improve this answer | |
  • I tried this, changing the code to(the CEWP im changing is webpartwpq21 as shown in dev tools): var linkText = $("#WebPartWPQ21").text(); $("#WebPartWPQ21").html("<a href=docLibUrl>" +linkText+ "</a>"); When I tried this, it didn't work unfortunately – Sabien Ambrose Aug 4 '16 at 16:15
  • Also, I don't think i will be able to use this... the url i enter into the <a> tag only allows me to append a url after: /sites/site1/sitePages/titleURLHere – Sabien Ambrose Aug 4 '16 at 16:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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