Jump to content

some problem call js to cut screen.


55143681

Recommended Posts

I use html2canvas.min.js to snap the form.

1.Add javaScript\html2canvas.min.js to serverModule's customFiles.

2.Add  function "canvasSaveAs"  to MainForm's Script.

function canvasSaveAs(uri, filename) {
    var link = document.createElement('a');
    if (typeof link.download === 'string') {
        link.href = uri;
        link.download = filename;
        document.body.appendChild(link);
        link.click();
        document.body.removeChild(link);
    } else {
        window.open(uri);
    }
}

3. call the function from my form.

void __fastcall TUniFormAlterMakePdf2::UniBitBtn1Click(TObject *Sender)
{

String   fName;
fName = "111capture" + FormatDateTime("yyyyMMddhhnnss", Now());
UniPanel1->JSInterface->JSCode(
    "html2canvas(document.querySelector(\"#"+ UniPanel1->JSId +"\")).then(function(canvas) {"
    +"   canvasSaveAs(canvas.toDataURL(), \""+ fName +"\");"
    +    "});"
    );
}

 

Problem:

In my new create project(http),that run normal,

but in my another project(https),that run with nothing,

why?

 

 

 

2023-02-04_231554.jpg

2023-02-04_231515.jpg

2023-02-04_231650.jpg

Link to comment
Share on other sites

11 hours ago, 55143681 said:

2.Add  function "canvasSaveAs"  to MainForm's Script.

function canvasSaveAs(uri, filename) {
    var link = document.createElement('a');
    if (typeof link.download === 'string') {
        link.href = uri;
        link.download = filename;
        document.body.appendChild(link);
        link.click();
        document.body.removeChild(link);
    } else {
        window.open(uri);
    }
}

Hello,

Then, also try to output this js function to a separate js file and include to the project.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...