Javascript download contents of a element [duplicate] - javascript

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Download textarea contents as a file using only Javascript (no server-side)
Basically I have a live html editor in javascript and I want to add the ability for the user to click a button or link and download their html document. My idea was just to download the file with the contents of the textarea element, but I can't seem to find out how.
I do have php if any server-side things are needed, it doesn't have to be strictly javascript but I want an option to do this. Thanks! And please comment because sometimes my questions can be rather confusing :|

Well there is an another simple way to do this on the client side itself, i believe that will be a best fit for you because, the html editing is done on the client side and you dont need any server data.
http://pixelgraphics.us/downloadify/test.html
the above component lets us download a content from the client side and WYSIWYG editor is a DIV with a Contenteditable true attribute which allows editing, so you can get the html content and pass it on to this component for client side download

Related

How to hide my javascript but let other download my webpage with thr script without them knowing? [duplicate]

This question already has answers here:
Can we hide javascript loading from the user?
(2 answers)
Closed 4 years ago.
So this is how it goes... I wanted to create a javascript that redirects links to my URL. So if anyone copies my webpage, they try changing my links, when they upload it to their server, her links will still redirect to my links. Is this possible with js? Or if I use PHP to hide the location of my js. I want that js to still work in the webpage they copied and use. Like a sticky clickjacker. That's hard to find and remove. Or if possible they cant at all.
I wanted to create a javascript that redirects links to my url.
This means that the user would have to already be at your URL because the JavaScript to redirect to your URL can only be added to pages that you control.
So if anyone copies my webpage, they try changing my links, when they
upload it to their server, her links will still redirect to my links.
As soon as they make a copy of your code, it's their code and they can upload it anywhere they want without your knowledge. And, if they can change your links, they can also just remove any JavaScript you may have had in the file.
What you want to do is not possible.

How to hide my HTML CSS JS code and show some random characters when someone view the source [duplicate]

This question already has answers here:
tools for obfuscating html and css [closed]
(2 answers)
Closed 6 years ago.
How to hide my HTML CSS JS source code and show some random characters when someone view the source by clicking the right button of mouse. I have given a link where the code is hidden and some characters have been shown. I have also attached an image for better understanding.
view-source:https://devitems.com/html/reflex-preview/reflex/index-3.html
You can first encode all your script content using encodeURI native browser function.
Inject to the page as plain text or local variable value
Then decode using decodeURI function
inject result into the page using document.write(decodedContent)
As I mentioned in my comment, there is simply no way to hide html, css or javascript. The example you have shown above it not hiding or encrypting anything. All you have to do, to get the 'real' html markup, is using for example PHP's urldecode function. Also, there is no reason to do so. If you have something, that no one should see, dont put it on the client side.
You can see its result here: http://pastebin.com/eZZTUNYA
Formatted version: http://pastebin.com/Gzg7jxT6
Short said: Dont even try to hide content. You cant.
If you still want to do, what your example did, you can do it with PHP as I said or in JavaScript directly. A PHP version would be:
$html = 'YOUR HTML CODE';
print urlencode($html);
Keep in mind, that because JavaScript has to decode it every time, it can cause higher loading times.

Accessing HTML <textarea> data and store them as file [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have following task:
I need to gather information from multiple <textarea> tags, format them a bit and save on hard drive preferably in CSV format.
Important note no. 1: that data source HTML document is a file on my local hard drive, it's not hosted on any server (this file is a product of export from some database management tool).
Important note no. 2: only script language engine available is python
I already do some effort on preparing some python script that embed CSS stylesheet links and JavaScript links into this HTML file to use and some jQuery library functions for displaying purposes.
Now, on specific action (i.e. "save" button click) I need to:
Search for filled <textarea> tags (jQuery job?)
Format them and glue in single variable preferably (jQuery as well)
Display "save as" dialogue
Save file on hard drive
Well as far as I know, JavaScript is not allowed to manipulate files on machine file system, so for writing file this should be some server-side script, is that correct?
Should this save script be triggered by "save as" button? (realized as submit form button)? If yes, can I run firstly some JavaScript function (gathering textarea data and format them) and later save this in file?
How this kind of data can be passed to this server-side script?
Thank you for all kind of help and advice.
EDIT:
I see that some users already point <a> tag with download attribute, but there is one additional issue: we have to assume IE as web browser, which by default does not support download attribute.
The correct answer was posted as a comment instead of as an answer for some reason. Code courtesy of gabrielperales:
JavaScript:
$(function(){
function toCSV(text){
var str= 'data:application/octet-stream;charset=utf-16le;base64,';
str += btoa(text);
return str;
}
$('#editor').on('change', function(){
$('#download').attr('href', toCSV($(this).val()));
});
});
HTML:
<textarea id="editor"></textarea>
<br/>
<a id="download" href="" download="file.csv">Download</a>

Inserting part of webpage into another using html only [duplicate]

This question already has answers here:
Can an iframe only show a certain part of the page?
(8 answers)
Closed 8 years ago.
I am trying to build a webpage using wix.com, and I want to include part of another website into mine. I can add html code. I am trying to get the featured poet on poetryoutloud.org into mine. This changed everyday and I only want this part of the webpage. I know that if I wanted to include the whole webpage I could use an iframe element, but this is only part of it
You can use an iframe
or alternatively you can use ajax, here an example using jQuery.
$("#yoursite-html").load("yoursite-html.php");
Please note if content is on another domain as described in your answer (CORS issue), you have to use a simple proxy example below:
PHP in file "yoursite-html.php":
echo file_get_contents("http://www.yoursite.com/");

Is it possible to read the pdf in html?

In my server i have a pdf. I want to view the pdf in html. But i want only show the first 3 pages only. If user select next it should show next 3 pages. Is it possible in HTML, JavaScript, Jquery?
Yes, it is possible.
You can go to this link.
https://github.com/mozilla/pdf.js/
This library is for reading PDF and and built with HTML5.
There is another Stack Overflow question regarding this issue.
How to Use pdf.js

Categories