Can I load something using AS3/SWF and then create a DOM element using javascript to display the loaded data, without having the browser to load the same data twice?
Yes, but it's not easy. You would have to convert the image to (for example a base64) string using a custom function looping through all the pixels of the bitmapdata, then send it to the webpage using an external interface, and then convert it back, either using the base64 to set the image url, or using Canvas to build the image manually from the pixels.
Perhaps I've missed something in what you've said but wouldn't it be quite easy to use the FileReference upload() method to send the file to a php script which then moves the file to the desired location on the server. If you wanted to have the image display in html without a new page load you could (I'm not too familiar with JS but I assume this is possible -> ) periodically check to see if your desired file is in the desired location. You could call a js function through ExternalInterface to tell the html page to expect this file and to check for it.
I've not tested this method so I can guarantee there are no flaws in it but it's the way I would attempt first. I'm assuming you're sending an image but it would work fine for any other file.
Related
I'm implementing a small image uploading function in my web page, nothing too fancy, and to that end, I think vgy.me is a good tool. From what I understand, we can upload an image to the site via a POST method in a form. It returns a JSON response for every image uploaded, which contains a link to the image among other things (important because I intend to use that link for future purposes). There's even a helpful little example of the same on its API page (link).
My question is, how can I get that JSON response for my use using vanilla JavaScript? My initial searches have turned out techniques which pertain to server-side, which obviously I can't implement because it isn't my server I'm using. Is there a way to use the default POST method of HTML to get the JSON value, or perhaps I've misinterpreted the instructions?
I'm not using the jQuery code given on the page, because I've no knowledge of any JavaScript framework, and I'd rather not simply copy and paste if I could help it.
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.
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/.
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.
My app loads a small HTML document that contains one image in a webview. How can I fetch this image and use it as a Bitmap object in my app?
I'm already using a JavaScriptInterface together with my webview for getting some other information, like passing booleans. Is it possible to pass an image aswell via the JavaScriptIterface? Is it a good idéa or is there a better way?
Take a look at this question: Get image data in JavaScript?
You might be able to draw the image on a (I presume hidden) Canvas, then Base64-encode it with toDataURL and pass that as a string through the JS interface then decode it on the Java side. I imagine it'll be slow, but it's worth a try.
I'm thinking of doing some online file manipulation for mobile users, the idea being that the user provides a URL to the file, then the file contents are modified by the JS, and can then be downloaded. But I haven't been able to figure out how to get the file when it's on a separate domain using just JS.
Is this possible? If so any hints or examples would be appreciated.
Just wanted to add that part of what I wanted to do was make it available without my hosting it. I'm thinking of something like a a file they can host somewhere,and then all of the bandwidth is their own...and that of wherever they are getting the file from of course.
The only way to load contents of a file on another domain is from within a <script> tag. This is how JSONP works. Look into getting your target file into this format.
The other way would be to use a local proxy. Create a web service method that loads and returns the contents of the file, then call that locally using your favorite JavaScript framework.
Depending on how you think of public webservices, and within some limitations I'm still mapping, you can do this using an ajax call to YQL, like so.
(will expand the answer later).
http://query.yahooapis.com/v1/public/yql?q=select%20%2a%20from%20data.uri%20where%20url=%22http://t3.gstatic.com/images?q=tbn:ANd9GcSyART8OudfFJQ5oBplmhZ6HIIlougzPgwQ9qcgknK8_tivdW0EOg%22
One of the limitations of this method is file size, it currently tops out at 25k.
I want to use JSChart (http://www.jscharts.com/) to generate a dynamic chart.
It uses a <canvas> object.
Furthermore I want to save the generated Chart as an image (to put in a pdf file) on the serverside.
Is it possible to save a JavaScript generated image as jpg or png on the serverside?
Preferably the solution should work with Ruby and Ruby On Rails.
I think this uses a <canvas> object to render the charts, can't tell without downloading and it requires registration, so no. If it does, perhaps take a look at Canvas2Image, that returns the canvas as a data URL, base64 encoded image, which could be sent back to the server via an AJAX call.
You can use http://xmlgraphics.apache.org/batik/ on the server to convert an SVG. It's the method used by highcharts to convert the graph generated by the application. See http://www.highcharts.com/docs/export-module/setting-up-the-server