So, is it possible to add a link as follows (or some equivalent to this)

<a href="javascript:somefunction()">Click Here</a>

into the Sharepoint page, but without using Content Editor Web Part.

Basically I want to open a new list item form from another site collection's list, and I need to open it in modal dialog, and I have working javascript function that allows me to do just that, but I can't call that function from the link itself because Sharepoint keeps stripping my javascript code when I'm saving the changes. In the other hand, CEWP can not be added to the sharepoint page itself.

Can I do anything about this?

  • Do you insert any customizations to your page like jQuery library or other javascripts scripts?
    – veritas
    Jan 17, 2013 at 21:01
  • Yes, I have a javascript function that is displaying a form in modal dialog. I can keep that script in masterpage, but I'd rather add it directly to the page itself
    – Eedoh
    Jan 17, 2013 at 21:03
  • 1
    Why you can't add Content Editor Web Part, it will not even be visible on the page... Just include the <script> block in that and from Web Part properties choose Chrome Type=None Jan 17, 2013 at 21:09
  • For some reason, Sharepoint does not allow me to add content editor on this page. It's disabled in the ribbon.
    – Eedoh
    Jan 17, 2013 at 21:10
  • Use SP Designer to add your javascript code. It will allow you to add.
    – sssreddy
    Jan 17, 2013 at 21:30

1 Answer 1


As your problem is to make a call to somefunction() try to bind it in your JavaScript file.

jQuery solution:


Pure JavaScript:

var anchor1 = document.getElementById("link-id");
anchor1.onclick = function() { 
    return false; 

Both require to add id attribute to your link (of course you may use also a class="..." or anything else).

  • Thanks for the reply, I liked this approach very much, and I was convinced it's gonna work, but it does not. When I do this the link is not clickable at all. It looks like a link, but mouse cursor now even does not change when I hover over it, nor anything happen when I click it.
    – Eedoh
    Jan 24, 2013 at 14:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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