2

How to convert the content of a div tag to an image and save it to a local folder via javascript ? I know there must be a way out but i am unable to find it . Any help would be greatly appreciated . Thanks in advance.

4
  • 2
    what-have-you-tried? Commented Oct 4, 2012 at 10:40
  • I tried rendering the canvas to an image and i achieved it but the problem is i want the entire div content converted to an image. Commented Oct 4, 2012 at 10:42
  • What does canvas have to do with your div element? Do you want to take a screen shot of your div element? Commented Oct 4, 2012 at 10:48
  • The canvas is within my div element. I have generated the graph dynamically through javascript and now i want the entire div to be converted to an image and saved to a local folder. Commented Oct 4, 2012 at 10:52

2 Answers 2

1

Canvas.drawImage supports Image, Canvas and Video elements. Some people say, that it may support DOMElement in the future.

There are many open-source browsers written in C (or C++). There is Emscripten project, which can convert C++ code to Javascript. So you can run your own browser inside a browser and use it to render your HTML.

Running browser inside a browser is not strange idea at all. E.g. there is a project, that emulates x86 machine in a browser - http://copy.sh/v24/.

Sign up to request clarification or add additional context in comments.

Comments

0

Javascript cannot write to the file system if that is what you are trying to achieve.

You can make use of HTML5's localStorage if you need to store strings in javascript but they are sandboxed within the browser.

To get the contents of most HTML elements you can use document.getElementById('theDiv').innerHTML to get what is between the <div></div> tags.

You can pass the result of innerHTML to a PHP page, and from there save it to file.

EDIT

Ok based our comments, I recommend you use PHP. You use document.getElementById('theDiv').innerHTML to send the html to a php page. From there use http://www.rabuser.info/painty.zip Download their 'painty.php' page and pass the html to it. painty.php in theory will generate an img out of the html.

7 Comments

This wont help i guess.I have generated the graph dynamically through javascript and now i want the entire div to be converted to an image and saved to a local folder. Your solution would just give me the html for that div.
You need to send the contents of the div to a PHP page to be saved. You also can't just save html to an Image, you will have to google how to do that using PHP.
Regardless of what you do, you cannot write to the file system from javascript. I use php to take html and generate a pdf from it.
Is there a way to do it with java ?
Maybe.. I don't know how you are going to get the canvas object to java. You are best off using a server-side scripting language such as PHP or ASP.net
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.