Using JavaScript URL in Calculated Columns

Friday, 9 January 2015

In SharePoint 2013, if you wanted to use JavaScript in a calculated column to open the URL in popup, here is the simple and quick method to achieve the result. Calculated column can render the HTML.
Add a column in your list/library, select its type as “Calculated” and add the following:


="<ahref='javascript:OpenPopUpPage('http://sitecollection/subsite /Lists/Tasks/AllItems.aspx')'>Click Me</a>"

When I tested the above code, it didn’t work for me. When I inspect the html, I found that JavaScript breaks the URL part the script.

So, I added modified the HTML part is calculated column as follows:

="<a href='#' onclick= 'Openlink()'>Click Me</a>"

Now add a content query web part in the page and add the following script in it.

<script langauage="javascript">
function Openlink()
{
  OpenPopUpPage('http://sitecollection/subsite/Lists/Tasks/AllItems.aspx');
}

</script>

You can modify it according to your requirements. Hope this will work.

2 comments

  1. Does not seem to work for me. I am using a script editor web part

    ReplyDelete
    Replies
    1. Hi Eric,

      Can you check console of your page for any errors. Let me know if it is still not working for you.

      Delete