Tuesday, December 2, 2014

How to change the Web Part Title URL behavior

With my morning cup of coffee I decided to start with something fairly simple (as a requirement) - it's in fact quite fresh as I had to do it for a client yesterday. It sounded like a 5 minute job, at the end it turned out more interesting. I've done this on 2010 and tested on 2013 as well - same behavior.

The requirement is to make just one specific webpart title URL to open in a new window while keeping all others (if any) loading in the same browser window. I am referring to the "Title URL" property, that is set in the Advanced section when you edit the web part.


There's no out of the box option to configure that, you could remove the URL, or point it to the page itself by changing it to #, but no way to make it open in a new window by adding "_blank" or something.

We can, however use a tiny piece of JavaScript to achieve that (tell SharePoint to do a specific thing when someone clicks on a specific URL) and we have a couple of options doing that thanks to jQuery.

Depending on whether that webpart is reused in many sites or web apps, you need to decide which method is the right one for you, You can do it globally with a full trust solution. That would have a wide impact on all web apps that have the solution deployed.
Let's assume you already have some branding solution in place which has a ccustomizations file in a .js format, you can add that piece of code in there. We are using the onload function here to ensure the site has fully loaded. If you have other JavaScript / jQuery customizations in the site that's the preferred method of calling jQuery to avoid any conflicts. The downside is that it will load only after all images are fully loaded, including some banner ads, etc.

In those example scripts I'm using the Microsoft CDN hosted version of the jQuery library, you can, however download a copy and store it locally on your site. Please make sure you use the https:// prefix in the reference if your site is accessed through SSL.

<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.9.0.js"</script><script>
window.onload = function() {
    if (window.jQuery) {
        jQuery(document).ready(function () {
                                jQuery('a[href^="http://www.contoso.com (replace with your URL)"]').click(function () {
                                jQuery(this).attr("target", "_blank");
                                });

                });
 </script>

The second way (more granular) is to store the script as a .js file in SharePoint and apply that on the page level by using the Content Editor webpart to call it. Here we're using the statement known as the ready event. This ensures that the code will run as soon as the document is ready for manipulation. Preferred method if we don't experience any conflicts with other customizations when trying to load it that way. Executes straight away without loading all the images first.

<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.9.0.js"</script><script>
$(document).ready(function(){
  $('a[href^="http://www.contoso.com (replace with your URL)"]').click(function() {
    $(this).attr("target","_blank");
  });
});
 </script>

You can also do that for all web part title URLs, the script will look like this:

<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.9.0.js"</script><script>
$(document).ready(function(){
$("h3.ms-WPTitle a").attr("target","_blank");
 });
 </script>

That's it. You can then export/import your CEWP and reuse it on any other page quickly. Don't forget to set its Chrome type to None so you don't actually display it on the web page.

72 comments:

  1. Not able to get this to work. My ExcelWebpart is on a WebPart page, single column. Tried placing it in page itself, placing code in Content Editor and calling code from Content Editor. Nothing has worked

    ReplyDelete
    Replies
    1. Hi James,

      Thanks for your comment.

      Please try and save one of the scripts as a .js file and upload it to your SharePoint farm. Ideally in the same site collection where it will be loaded. Then call it from a Content Editor Web part.

      If that does not work, use Developer Tools in your browser to see if the .js is trying to load at all.
      Might be wrong method of calling it, or a setting in the browser (much less likely though).

      Cheers,

      Dimitar

      Delete
  2. We have a well-defined process and a dedicated team that will keep you well informed before every step we take. We make sure to get you the top quality website that result in more quality leads and sales. web development services in usa

    ReplyDelete
  3. You must indulge in a contest for one of the greatest blogs over the internet. Ill suggest this web site! design agency san francisco

    ReplyDelete
  4. This plot doesn’t reveal itself; it has to be explained. web design san francisco

    ReplyDelete
  5. Awesome post, will be a daily visitor from now on! design firms los angeles

    ReplyDelete
  6. I’m curious to find out what blog platform you are utilizing? I’m experiencing some small security issues with my latest blog and I would like to find something more safe. Do you have any solutions? web design agency los angeles

    ReplyDelete
  7. Along these lines, despite the fact that you have your site place under system uptime you may be 100% safe.web hosting near me

    ReplyDelete
  8. cleaning supplies should have earth friendly organic ingredients so that they do not harm the environment“ web design la

    ReplyDelete
  9. I dont think Ive scan anything like this before. So good to find somebody with some original thoughts on this subject. nice one for starting this up. This site is something that is needed on the web, someone with a little originality. Good job for bringing something new to the internet! website design

    ReplyDelete
  10. Yay google is my world beater helped me to find this great web site ! . web design tips

    ReplyDelete
  11. It’s appropriate time to make some plans for the future and it’s time to be happy. I have read this post and if I could I wish to suggest you some interesting things or tips. Maybe you could write next articles referring to this article. I wish to read more things about it! top web design companies

    ReplyDelete
  12. This is such a great resource that you are providing and you give it away for free. I love seeing blog that understand the value of providing a quality resource for free. SEO Company Vancouver

    ReplyDelete
  13. Thanks, foг ones marvelous posting! I genuinely enjoyed reading it, you miggһt Ƅe a great author. I wiⅼl made certain to booҝmark your blog and ѡill often come back sometime soon. I want to encoᥙrage yourself to continue your great job, have a nice evening!
    Web Development Course
    best web development courses
    web development classes
    web development course near me
    Web Development Training
    training on web development
    web development training program
    web development training course
    web development summer training

    ReplyDelete
  14. Promptly this kind of extraordinary internet site must unquestionably become identified inside of every one of the web site a lot of people, as a result of meticulous posts or perhaps critiques or perhaps comments. web design companies denver

    ReplyDelete
  15. This is precarious since, supposing that your lone promoting will be Natural Pursuit/PPC you may need a watchword spam type area name. Webdesign

    ReplyDelete
  16. It is important to draw a line between work time and relaxation time, saving certain pieces of the day for working and certain parts to manage different duties. On the off chance that no line is drawn, you'll discover little tasks: 'making the children a bite', 'rushing to the shops', 'browsing your messages', take up an enormous segment of the day. The appropriate response is to make an everyday practice for your independent work: have similar segments of the day put in a safe spot for work, plan sensible breaks and adhere to the arranged completing time.Professional graphic design

    ReplyDelete
  17. Very informative post! There is a lot of information here that can help any business get started with a successful social networking campaign. web-agency

    ReplyDelete
  18. I was reading some of your content on this website and I conceive this internet site is really informative ! Keep on putting up. creare sito ecommerce

    ReplyDelete
  19. Hey what a brilliant post I have come across and believe me I have been searching out for this similar kind of post for past a week and hardly came across this. Thank you very much and will look for more postings from you. creare sito web

    ReplyDelete
  20. It is truly a well-researched content and excellent wording. I got so engaged in this material that I couldn’t wait reading. I am impressed with your work and skill. Thanks. online customer service outsource

    ReplyDelete
  21. This is a framework of what we expect soon to the extent SEO business is of concern.
    Website laten maken

    ReplyDelete
  22. Another central issue you ought to characterize is whether the web designer can make you a 100% custom web website. Webdesign Genk

    ReplyDelete
  23. This blog is really great. The information here will surely be of some help to me. Thanks!. 웹툰 다시보기

    ReplyDelete
  24. I have read your blog it is very helpful for me. I want to say thanks to you. I have bookmark your site for future updates. Webdesign Antwerpen

    ReplyDelete
  25. Very good points you wrote here..Great stuff...I think you've made some truly interesting points.Keep up the good work. Webdesign bureau

    ReplyDelete
  26. Thank you for taking the time to publish this information very useful! Webdesign

    ReplyDelete
  27. I wanted to thank you for this excellent read!! I definitely loved every little bit of it. I have you bookmarked your site to check out the new stuff you post. WordPress Developer Brisbane

    ReplyDelete
  28. There are a few sorts of websites like Internet business destinations, online media locales, layout based destinations, CSS websites and a few more. Webdesign-seo-limburg.be

    ReplyDelete
  29. Hello, this weekend is good for me, since this time i am reading this enormous informative article here at my home.
    quenza app

    ReplyDelete
  30. Hello, this weekend is good for me, since this time i am reading this enormous informative article here at my home.
    คลินิกเสริมความงาม

    ReplyDelete
  31. When you want to have a website for your small business, the best way is to get it designed by a professional web design company. However, you need to look at a few factors before selecting the company to do the job for you. It is a good idea to see what they are. Social Media Creation, Design, Management and Optimisation

    ReplyDelete
  32. That is enterprise associated knowledge gaining article. This put up is truly the first-class on this valuable subject matter.
    Idn Slot

    ReplyDelete

  33. Superbly written article, if only all bloggers offered the same content as you, the internet would be a far better place..
    먹튀검증사이트

    ReplyDelete
  34. I am hoping the same best effort from you in the future as well. In fact your creative writing skills has inspired me.
    메이저놀이터

    ReplyDelete
  35. Thank you for some other informative blog. Where else could I get that type of information written in such an ideal means? I have a mission that I’m just now working on, and I have been at the look out for such information.
    SEO Company Australia

    ReplyDelete
  36. Thank you again for all the knowledge you distribute,Good post. I was very interested in the article, it's quite inspiring I should admit. I like visiting you site since I always come across interesting articles like this one.Great Job, I greatly appreciate that.Do Keep sharing! Regards,
    토토사이트

    ReplyDelete
  37. Your blog has piqued a lot of real interest. I can see why since you have done such a good job of making it interesting. I appreciate your efforts very much. convert pdf to docx

    ReplyDelete
  38. Thank you again for all the knowledge you distribute,Good post. I was very interested in the article, it's quite inspiring I should admit. I like visiting you site since I always come across interesting articles like this one.Great Job, I greatly appreciate that.Do Keep sharing! Regards,
    uk spinning bike

    ReplyDelete
  39. Its a great pleasure reading your post.Its full of information I am looking for and I love to post a comment that "The content of your post is awesome" Great work.
    Aplikasi saham rekomendasi

    ReplyDelete
  40. I like this post,And I figure that they having a ton of fun to peruse this post,they might take a decent site to make an information,thanks for sharing it to me.
    Mia Khalifa Biography

    ReplyDelete
  41. I like this post,And I figure that they having a ton of fun to peruse this post,they might take a decent site to make an information,thanks for sharing it to me.
    Industrial Cleaning Services Livonia MI

    ReplyDelete
  42. I'll come often. I hope you prosper.Please write good things from now on. 먹튀신고

    ReplyDelete
  43. I'm surprised there's such a wonderful article.every pressured me to take a look at and do it 토토사이트

    ReplyDelete
  44. He's growing up. It's growing. That's a really good piece of data. Amazing. 메이저사이트

    ReplyDelete
  45. Your blog is fabulous, superior give good results... Seen a large number of definitely will understand everybody even in the event they do not take the time to reveal.
    refomas baños zaragoza

    ReplyDelete
  46. This is one very interesting post. I like the way you write and I will bookmark your blog to my favorites.메이저놀이터

    ReplyDelete
  47. Nice information, valuable and excellent design, as share good stuff with good ideas and concepts.먹튀검증사이트

    ReplyDelete

  48. 동행복권에서 진행하는 5분마다 추첨하는 추첨식 복권입니다. 게임방식 : 숫자선택 게임, 숫자합 숫자선택게임 : 1~28까지 일반볼 5개, 0~9까지 파워볼 1개, 총 6개 숫자 선택 숫자합게임 : 일반볼 홀/짝 게임, 대/중/소 게임, 숫자합 구간선택 게임, 파워볼 구간선택 게임
    파워볼전용사이트

    ReplyDelete
  49. Excellent information on your blog, thank you for taking the time to share with us. Amazing insight you have on this, it's nice to find a website that details so much information about different artists.
    residence permit turkey

    ReplyDelete
  50. Keep up the good work , I read few posts on this web site and I conceive that your blog is very interesting and has sets of fantastic information. 먹튀사이트

    ReplyDelete
  51. I really like your writing style, great information, thankyou for posting. แทงบอล i99pro

    ReplyDelete
  52. Great post, you have pointed out some fantastic points , I likewise think this s a very wonderful website. 메이저사이트

    ReplyDelete
  53. Cool stuff you have got and you keep update all of us. 안전놀이터

    ReplyDelete
  54. Wow, What an Outstanding post. I found this too much informatics. It is what I was seeking for. I would like to recommend you that please keep sharing such type of info.If possible, Thanks. here

    ReplyDelete
  55. You have done a great job on this article. It’s very readable and highly intelligent. You have even managed to make it understandable and easy to read. You have some real writing talent. Thank you. 안전놀이터

    ReplyDelete
  56. This is actually the kind of information I have been trying to find. Thank you for writing this information. 온라인릴게임

    ReplyDelete
  57. I read that Post and got it fine and informative. Kanada Visum

    ReplyDelete
  58. Thanks for sharing your wealthy information. This is one of the excellent posts which I have seen. I go through your all of your blog, but this blog is the best one. It is really what I wanted to see hope in future you will continue for sharing such an excellent post
    mở lại đường bay việt nam - hàn quốc

    lịch bay từ úc về việt nam hôm nay

    vé máy bay từ san francisco về việt nam

    Vé máy bay từ Đài Trung về Việt Nam

    có vé máy bay từu mỹ về việt nam chưa

    khi nào có chuyến bay từ canada về việt nam

    ReplyDelete
  59. Nice to be visiting your blog once more, it has been months for me. Well this article that ive been waited for therefore long. i want this article to finish my assignment within the faculty, and it has same topic together with your article. Thanks, nice share. 토토사이트

    ReplyDelete
  60. Thank you so much as you have been willing to share information with us. We will forever admire all you have done here because you have made my work as easy as ABC. 팔팔카

    ReplyDelete
  61. Our final recommendation is a pretty obvious and simple one, to most people, but we still speak to developers who don't use any form of source control. https://www.sandeepmehta.co.in/affordable-seo-services-delhi/

    ReplyDelete
  62. What is an outstanding post! “I’ll be back” (to read more of your content). Thanks for the nudge! 대전건마

    ReplyDelete
  63. Online achievement of your website relies upon preparing and executing our "add unique quality substance frequently" procedure alongside these custom CMS web design spending tips.
    https://onohosting.com/

    ReplyDelete
  64. Wow, What a Excellent post. I really found this to much informatics. It is what i was searching for.I would like to suggest you that please keep sharing such type of info.Thanks สมัครงาน คลินิกเสริมความงาม

    ReplyDelete
  65. Fabulous post, you have denoted out some fantastic points, I likewise think this s a very wonderful website. I will visit again for more quality contents and also, recommend this site to all. Thanks. nursing test bank

    ReplyDelete
  66. At Inovi, we’re committed to achieving the highest success rates while providing personalized care to our patients. Our Houston location offers expert care and is home to our state-of-the-art embryology lab. click reference

    ReplyDelete
  67. RSJ is at the top of our game when it comes to tax-minimization strategies for asset growth, protection and transfer. We have always known that something was missing from traditional estate planning for high-net-worth families. https://www.rsjcpa.com/

    ReplyDelete
  68. With liposuction, the surgeon can remove stubborn fat deposits, improve your physical appearance by using contouring procedures to give you pleasing curves in all the right places. Look At This

    ReplyDelete
  69. I am unable to read articles online very often, but I’m glad I did today. This is very well written and your points are well-expressed. Please, don’t ever stop writing. 토토사이트

    ReplyDelete