开发者

TinyMCE : Remove Javascript from head

I am allowing Full Page Editing whi开发者_开发知识库ch has and tags as well . I added as an invalidelement and it gets removed if I add inside the body but it doesnt get removed if I have inside the head element. Is there any way to handle that ?


I'm not able to understand your question very clearly. Though, I assume this might be the problem you are facing.

You are setting the "invalid_elements" while initializing in tinymce.

Possible reasons :

When you add it under the head section, it is certain that the script is defined before it is used. Also code in the head tag will be executed before that in the body(order of page loading).

When using JavaScript in a frames you must place all the JavaScript with the HEAD elements otherwise you cannot guarantee that the frames will be displayed correctly. TinyMce uses iframes to simulate whatever you type into rich text. So there might be a conflict due to this situation.


Here is a code snippet to be used for that particular use case:

    switchStyle: function(url,tiny_id,url_to_replace){
        ed = tinymce.get(tiny_id);

        doc = $(ed.getBody().ownerDocument);

        // get stylesheet info alternative
        sheets = ed.getParam('content_css_alt');
        sheets_urls = [];

        if (url_to_replace){
            sheets_urls.push(url_to_replace);
        }
        else{
            sheets_urls.push(ed.getParam('content_css'));
            if (typeof sheets == "string"){
                sheets_urls.push(sheets);

            }
            else {
                for (var i = 0; i < sheets.length; i++) {
                    sheets_urls.push(sheets[i].url);
                }
            }
        }

        // remove all stylesheets from sheets_urls
        doc.find('link').each(function() {

            if (tinymce.inArray(sheets_urls, $(this).attr('href').split('?')[0]) !== -1) {
                $(this).remove();
            }
        });

        // set stylesheet
        doc.find('head:first').append('<link rel="stylesheet" href="' + url + '"');

    },
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜