Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

In a sub-site, I input HTML through the WI using the HTML Source edit button in the ribbon. This is what I enter:

 <a onclick="javascript:NewItem2(event, &quot;https://website/sites/site/_layouts/listform.aspx?PageType=8&amp;ListId={AEB087E7-DA21-4DA8-BB9A-9073382B3ED4}&amp;RootFolder=&quot;);javascript:return false;"href="/_layouts/listform.aspx?PageType=8&amp;ListId={AEB087E7-DA21-4DA8-BB9A-9073382B3ED4}&amp;RootFolder=" target="_self">

When I save the code, this is what it saves:

 <a href="/_layouts/listform.aspx?PageType=8&amp;ListId=%7bAEB087E7-DA21-4DA8-BB9A-9073382B3ED4%7d&amp;RootFolder=">

This code is followed by code for a linked image. Any idea why SP would do this? I have seen it update other code items to suit itself, but nothing to this extent.

share|improve this question
1  
You might find these articles useful blog.pathtosharepoint.com/?s=CEWP&submit=Search –  Christophe Feb 10 at 20:26
add comment

1 Answer

up vote 5 down vote accepted

Adding javascript to a Wiki page content is the same as adding it to a CEWP. The end result is that SharePoint will strip out the code and convert hyperlinks with JavaScript to useless tags, as you showed.

The only solution, which by the way is also a best practice, is to add a CEWP* to your page and link an external javascript file (that you'll have uploaded to a doc library in your site) in the content link box.

[*] As an alternative to the commonly proposed workaround of using a CEWP, you can make use of the HTML Form web part, which allows you to put javascript code within it, without incurring in your code being stripped out.

share|improve this answer
    
The CEWP works out. I have some formatting issues, but overall does what I need it to do. Had not thought of doing it this way ... guess that comes from being self taught in SP. Some best practices from formal training can sometimes can be a good thing ;-) –  Paulster2 Feb 10 at 19:12
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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