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

I'm using PIE.js to force IE7 to use CSS3 styles. However, whenever an element on my SharePoint page contains the class that PIE is supposed to style, it actually inserts the code into the html when rendered. Then upon editing the page, the code is added again on top of the old code. So at first I start with a simple tag with a class, then I end up with 200+ lines of code.

The question: How can I prevent SharePoint from literally writing the rendered code from the javascript?

I know this is a larger issue than just PIE.js...any javascript append or prepend actually prints the code in SharePoint.

share|improve this question
add comment

3 Answers

up vote 1 down vote accepted

The root of the problem is that PIE.js is rewriting Html within the content itself when the page is being edited and the simplest fix for it is to not include PIE.JS if the page is being edited.

How you do this depends entirely on your environment and comfort level. There are Javascript methods to determine if the page is being edited, page layout/master page methods and code methods where you can conditionally register the script include, like Abe suggested.

share|improve this answer
1  
Excellent! This lead to the answer. I also had to be sure that my css wasn't attempting to style the element while in "design" mode. The css styles have a "behavior" attribute that calls the PIE.js file which will cause the problems. I added the styled classes via javascript which was only running during "browse" mode. –  Barry Jul 18 '12 at 18:43
add comment

Why this is happening really depends on how you are adding the script. In the past I have used RegisterClientScriptInclude to add a script once. In order for this to work you need to include the same script with the same key everywhere. This way it will not be added if the script is already on the page. Example:

Page.ClientScript.RegisterClientScriptInclude("MultiPartJS", "/_layouts/MNCAssets/Scripts/multiPart.min.js");

share|improve this answer
add comment

If you want Javascript to only run once you could always do a.... (This will make sure it only runs once even if the JavaScript is contained in multiple files)

var myObj = myObj || {};

$(document).ready(function () {
    if (!(myObj.token)) {
        // Code goes here
        myObj.token = {};  // this ensure we won't enter the if block the next time
    }
})
share|improve this answer
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.