admin管理员组

文章数量:1290329

I am having a really odd problem. When I used my local summernote files to load the text editor, ".summernote is not a function" happened. However, if I used the cdn files to load the editor, everything went fine. Here is my HTML header code:

<!DOCTYPE html>
<html dir="ltr" lang="en">
<head>
    <meta charset="UTF-8"/>
    <title><?php echo $title; ?></title>
    <base href="<?php echo $base; ?>"/>
    <?php if ($description) { ?>
        <meta name="description" content="<?php echo $description; ?>"/>
    <?php } ?>
    <?php if ($keywords) { ?>
        <meta name="keywords" content="<?php echo $keywords; ?>"/>
    <?php } ?>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0"/>
    <link href="favicon.ico" rel="icon">
    <!-- include jquery -->
    <script type="text/javascript" src="javascript/jquery/jquery-2.1.1.min.js"></script>
    <!-- include libraries BS3 -->
    <script type="text/javascript" src="javascript/bootstrap/js/bootstrap.min.js"></script>
    <link href="stylesheet/bootstrap.css" type="text/css" rel="stylesheet"/>
    <!-- include font-awesome-->
    <link href="javascript/font-awesome/css/font-awesome.min.css" type="text/css" rel="stylesheet"/>
    <!-- include datetimepicker-->
    <script src="javascript/jquery/datetimepicker/moment.js" type="text/javascript"></script>
    <script src="javascript/jquery/datetimepicker/bootstrap-datetimepicker.min.js" type="text/javascript"></script>
    <link href="javascript/jquery/datetimepicker/bootstrap-datetimepicker.min.css" type="text/css" rel="stylesheet" media="screen"/>
    <!-- include customer stylesheet-->
    <link type="text/css" href="stylesheet/stylesheet.css" rel="stylesheet" media="screen"/>
    <!--include customer js-->
    <script src="javascript/mon.js" type="text/javascript"></script>

    <?php if ($styles) { ;?>
        <?php foreach ($styles as $style) { ;?>
            <link href="<?php echo $style;?>" rel="stylesheet"></link>
        <?php } ;?>
    <?php } ;?>
    <?php if ($scripts) { ;?>
        <?php foreach ($scripts as $script) { ;?>
            <script href="<?php echo $script;?>" type="text/javascript"></script>
        <?php } ;?>
    <?php } ;?>

<!--    <link href=".8.2/summernote.css" rel="stylesheet">-->
<!--    <script src=".8.2/summernote.js"></script>-->

I tried to load the local files directly instead of echo them by PHP, but the problem is still there.

I checked every href, there is no dead link.

Then I created a pure HTML called test.html file underneath the javascript folder, and the text editor loaded fine by using local files.

By the way the framework I'm using is CI, and the file structure is:

root
├──javascript
   ├──bootstrap
   ├──jquery
   ├──summernote
   ├──font-awesome
   ├──test.html

I am having a really odd problem. When I used my local summernote files to load the text editor, ".summernote is not a function" happened. However, if I used the cdn files to load the editor, everything went fine. Here is my HTML header code:

<!DOCTYPE html>
<html dir="ltr" lang="en">
<head>
    <meta charset="UTF-8"/>
    <title><?php echo $title; ?></title>
    <base href="<?php echo $base; ?>"/>
    <?php if ($description) { ?>
        <meta name="description" content="<?php echo $description; ?>"/>
    <?php } ?>
    <?php if ($keywords) { ?>
        <meta name="keywords" content="<?php echo $keywords; ?>"/>
    <?php } ?>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0"/>
    <link href="favicon.ico" rel="icon">
    <!-- include jquery -->
    <script type="text/javascript" src="javascript/jquery/jquery-2.1.1.min.js"></script>
    <!-- include libraries BS3 -->
    <script type="text/javascript" src="javascript/bootstrap/js/bootstrap.min.js"></script>
    <link href="stylesheet/bootstrap.css" type="text/css" rel="stylesheet"/>
    <!-- include font-awesome-->
    <link href="javascript/font-awesome/css/font-awesome.min.css" type="text/css" rel="stylesheet"/>
    <!-- include datetimepicker-->
    <script src="javascript/jquery/datetimepicker/moment.js" type="text/javascript"></script>
    <script src="javascript/jquery/datetimepicker/bootstrap-datetimepicker.min.js" type="text/javascript"></script>
    <link href="javascript/jquery/datetimepicker/bootstrap-datetimepicker.min.css" type="text/css" rel="stylesheet" media="screen"/>
    <!-- include customer stylesheet-->
    <link type="text/css" href="stylesheet/stylesheet.css" rel="stylesheet" media="screen"/>
    <!--include customer js-->
    <script src="javascript/mon.js" type="text/javascript"></script>

    <?php if ($styles) { ;?>
        <?php foreach ($styles as $style) { ;?>
            <link href="<?php echo $style;?>" rel="stylesheet"></link>
        <?php } ;?>
    <?php } ;?>
    <?php if ($scripts) { ;?>
        <?php foreach ($scripts as $script) { ;?>
            <script href="<?php echo $script;?>" type="text/javascript"></script>
        <?php } ;?>
    <?php } ;?>

<!--    <link href="http://cdnjs.cloudflare./ajax/libs/summernote/0.8.2/summernote.css" rel="stylesheet">-->
<!--    <script src="http://cdnjs.cloudflare./ajax/libs/summernote/0.8.2/summernote.js"></script>-->

I tried to load the local files directly instead of echo them by PHP, but the problem is still there.

I checked every href, there is no dead link.

Then I created a pure HTML called test.html file underneath the javascript folder, and the text editor loaded fine by using local files.

By the way the framework I'm using is CI, and the file structure is:

root
├──javascript
   ├──bootstrap
   ├──jquery
   ├──summernote
   ├──font-awesome
   ├──test.html
Share Improve this question asked Dec 12, 2016 at 8:21 SSDSSD 2951 gold badge4 silver badges15 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 4

I don't think you're including your scripts in the right order.

When you loaded from the CDN, your order looked something like this:

<script src="http://cdnjs.cloudflare./ajax/libs/summernote/0.8.2/summernote.js"></script>
<script src="javascript/mon.js" type="text/javascript"></script>

. . . which is logical, because you want to be sure that summernote is loaded by the time your main JS code executes.

However, your PHP dependency management code was injecting the tags linking to local files after that same script. Basically, dump all of that logic before your customer's script too:

<?php if ($styles) { ;?>
    <?php foreach ($styles as $style) { ;?>
        <link href="<?php echo $style;?>" rel="stylesheet"></link>
    <?php } ;?>
<?php } ;?>
<?php if ($scripts) { ;?>
    <?php foreach ($scripts as $script) { ;?>
        <script src="<?php echo $script;?>" type="text/javascript"></script>
    <?php } ;?>
<?php } ;?>

<script src="javascript/mon.js" type="text/javascript"></script>

(Also note that in your PHP you wrote href instead of src for your script tag generation.)

For me, I wanted to use summer note with bootstrap4, I copied the below code from the official documentation but it didn't work, I realized afterwards that I was embedding a newer bootstrap version at the beginning of my page (I was reaching out to some bootstrap files located at the assets), I removed that line and everything went just fine:

 <script src="https://code.jquery./jquery-3.5.1.min.js" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>

<link rel="stylesheet" href="https://stackpath.bootstrapcdn./bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<script src="https://stackpath.bootstrapcdn./bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>

<link href="https://cdn.jsdelivr/npm/[email protected]/dist/summernote-bs4.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr/npm/[email protected]/dist/summernote-bs4.min.js"></script>

I got the same error after some research I found that jquery version and summernote version must match

<script src="https://stackpath.bootstrapcdn./bootstrap/3.4.1/js/bootstrap.min.js"></script>
  <link href="https://cdnjs.cloudflare./ajax/libs/summernote/0.8.20/summernote-bs4.min.css" rel="stylesheet">
  <script src="https://cdnjs.cloudflare./ajax/libs/summernote/0.8.20/summernote.min.js"></script>
<script src="https://cdnjs.cloudflare./ajax/libs/bootstrap/5.3.0/js/bootstrap.min.js"></script>   

above I provide latest version of both and it works perfectly fine.

here is the whole code:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Summernote</title>
  <script src="https://stackpath.bootstrapcdn./bootstrap/3.4.1/js/bootstrap.min.js"></script>
  <link href="https://cdnjs.cloudflare./ajax/libs/summernote/0.8.20/summernote-bs4.min.css" rel="stylesheet">
  <script src="https://cdnjs.cloudflare./ajax/libs/summernote/0.8.20/summernote.min.js"></script>
<script src="https://cdnjs.cloudflare./ajax/libs/bootstrap/5.3.0/js/bootstrap.min.js"></script>  
</head>
<body>
  <div id="summernote"><p>Hello Summernote</p></div>
  <script>
    $(document).ready(function() {
        $('#summernote').summernote();
    });
  </script>
</body>
</html>

本文标签: javascriptError summernote is not a function when using local filesStack Overflow