简体   繁体   中英

How to call tiny_mce.init from external javascript file

I know almost nothing about javasrcipt, but I do know I should be able to do this.

I have several different tinymce.init calls that I would like to make. They work fine if I load them in the page's head but not if I move them to an external .js file. Can someone tell me what is wrong with the following?

My page file header:

<head id="Head1" runat="server">
    <title></title>
    <script type="text/javascript" src="../Scripts/tiny_mce/tiny_mce_src.js"></script>
    <script type="text/javascript" src="../Scripts/load_tinymce.js"></script>
</head>

And my external file (load_tinymce.js):

tinyMCE.init({
    mode: "specific_textareas",
    editor_selector: "StandardEditBox",
    theme: "advanced",
    theme_advanced_buttons1: "bold,italic,underline,|,sub,sup,charmap",
    theme_advanced_toolbar_location: "top",
    theme_advanced_toolbar_align: "left",
    theme_advanced_statusbar_location: "none",
    forced_root_block: false,
    height: "50",
    encode: "xml",
    theme_advanced_resizing: false,
    setup: function (ed) {
        ed.onSaveContent.add(function (i, o) {
            o.content = o.content.replace(/&#39/g, "&apos");
            });
    }
});

tinyMCE.init({
    mode: "specific_textareas",
    editor_selector: "CommentsTextBox",
    theme: "advanced",
    theme_advanced_buttons1: "bold,italic,underline,|,sub,sup,charmap",
    theme_advanced_toolbar_location: "top",
    theme_advanced_toolbar_align: "left",
    theme_advanced_statusbar_location: "none",
    forced_root_block: false,
    height: "150",
    width: "580",
    encode: "xml",        
    theme_advanced_resizing: false,
    setup: function (ed) {
            ed.onSaveContent.add(function (i, o) {"&apos");
        });
    }
});

I feel like there should be something else in my .js file but I don't know what it could be.

Verify that your script src is actually correct.

Try using the following:

   <script type="text/javascript" src="/Scripts/tiny_mce/tiny_mce_src.js"></script>
   <script type="text/javascript" src="/Scripts/load_tinymce.js"></script>

This will load absolute from the root. Assuming your Scripts folder is at root level.

I removed the .. from your src - as this is telling the page to look one folder back, relative from itself, for the scripts folder.

UPDATE

Change your src to:

       <script type="text/javascript" src="Scripts/tiny_mce/tiny_mce_src.js"></script>
        <script type="text/javascript" src="Scripts/load_tinymce.js"></script>

Removed the /

Also, if you haven't done so, install Firebug for firefox. It will help you pin down the exact problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM