最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Why is html2canvas not defined? - Stack Overflow

programmeradmin4浏览0评论

If I'm calling this function, getting always "html2canvas is not defined".

makeScreenshot: function(button)
{
    debugger;
    html2canvas(document.body, {
        Uncaught ReferenceError: html2canvas is not defined
        onrendered: function(canvas) {
            document.body.appendChild(canvas);
        }
    });
},

but why? I have a class of it... like in tutorial written about it. Does anyone have a solution?

I suppose I need to include html2canvas here, but I don't know how.

Ext.define("TEST.controller.Desktop", {
    extend: "Ext.app.Controller",

    views: [
        "desktop.Desktop",
        //"desktop.TaskBar",
        "desktop.Toolbar",
        "desktop.DataprovidersDataView",
        "configuration.UploadFileWindow"
    ],

refs: [{
    ref: "viewport",
    selector: "viewport"
}, {

If I'm calling this function, getting always "html2canvas is not defined".

makeScreenshot: function(button)
{
    debugger;
    html2canvas(document.body, {
        Uncaught ReferenceError: html2canvas is not defined
        onrendered: function(canvas) {
            document.body.appendChild(canvas);
        }
    });
},

but why? I have a class of it... like in tutorial written about it. Does anyone have a solution?

I suppose I need to include html2canvas here, but I don't know how.

Ext.define("TEST.controller.Desktop", {
    extend: "Ext.app.Controller",

    views: [
        "desktop.Desktop",
        //"desktop.TaskBar",
        "desktop.Toolbar",
        "desktop.DataprovidersDataView",
        "configuration.UploadFileWindow"
    ],

refs: [{
    ref: "viewport",
    selector: "viewport"
}, {
Share Improve this question edited Aug 14, 2013 at 13:14 rink.attendant.6 46.2k64 gold badges110 silver badges157 bronze badges asked Aug 14, 2013 at 12:49 r.rr.r 7,15329 gold badges89 silver badges132 bronze badges 4
  • 1 How are you including html2canvas on your page? How are you including your own code on your page? – Dancrumb Commented Aug 14, 2013 at 12:52
  • I just added html2canvas.js into my classes, and calling html2canvas as method from desktop Controller... – r.r Commented Aug 14, 2013 at 12:53
  • 1 Can you post some code? For instance, how did you include html2canvas within your html page? – Nicolae Olariu Commented Aug 14, 2013 at 12:58
  • I'm working with Ext.JS and don't have a html pages. But i will show what I am doing... – r.r Commented Aug 14, 2013 at 12:59
Add a ment  | 

3 Answers 3

Reset to default 6

Ext doesn't know anything about classes not defined as part of it's class system, you need to include the JS file using a script tag in your html.

If it's a Node.js application, try importing using the following code in the JS file in which the function's used:

import html2canvas from 'html2canvas';
// Or
const html2canvas = require('html2canvas');

For react, vuejs, or Angular2+ applications, you can use the following in your JS or TS file:

import html2canvas from 'html2canvas';

You need to include required library, in my case:

  1. plugins\export\libs\blob
  2. plugins\export\libs\classList
  3. plugins\export\libs\blob\fabric.js
  4. plugins\export\libs\blob\jszip
  5. plugins\export\libs\blob\pdfmake
  6. plugins\export\libs\blob\xlsx
发布评论

评论列表(0)

  1. 暂无评论