Skip to main content
Question

How to access "document" in code.ts?

  • October 3, 2022
  • 1 reply
  • 768 views

Oscar_Yiu

Document is undefined in code.ts. I can’t createElement(‘a’) for download some styles data I get from figma API.
How to access “document” in code.ts?
So user can download the json generate by the plugin?

function downloadObjectAsJson(exportObj, exportName){
var dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(exportObj));
var downloadAnchorNode = document.createElement('a');
downloadAnchorNode.setAttribute("href", dataStr);
downloadAnchorNode.setAttribute("download", exportName + ".json");
document.body.appendChild(downloadAnchorNode); // required for firefox
downloadAnchorNode.click();
downloadAnchorNode.remove();
}

1 reply

Gleb
  • Power Member
  • 4707 replies
  • October 3, 2022

You can’t do that in code.ts, this needs to be done in the UI of the plugin.

figma.com

Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings