/    Sign up×
Community /Pin to ProfileBookmark

Save part of the page to file.

I am looking for some java script to save a part of my HTML/PHP page.
ther are some things i have bin trying. but the most of it dont work for me.

This is a example of the code i have already.

[QUOTE]

<html>
<head>
<title>Save part of the page to file</title>
</head>
<body>

<div id=”text1″>
Part 1 of te text here
</div><br>

<div id=”text2″>
Part 2 of te text here
</div><br><br>

<button onClick=”Save();”>save part 1</button>

<script type=”text/javascript”>

function Save(){
document.execCommand(“SaveAs”)
}
</script>
</body>
</html>

[/QUOTE]

It works just fine. but it saves the complete page and not only part 1 of my page.

i think i need the folowing code

[QUOTE]

document.getElementById(“text1”);

[/QUOTE]

but i dont realy know how to get this function in, and i did not succeed to find the right code on the WWW.

It would be nice if somone could help me out. ?

//Potzet

to post a comment
JavaScript

8 Comments(s)

Copy linkTweet thisAlerts:
@sovikFeb 08.2007 — You can open a popup widnow with just the information you want to be saved and execute saveAs on the popup (child) window.
Copy linkTweet thisAlerts:
@potzetauthorFeb 08.2007 — first of all, Thank you for your reply!! ?

I read something like that before. and have been trying to put something like this in to my page. but I stopped trying when i notice that it didn’t work. probably cause i did something wrong.. >AGAIN!!< :p [/QUOTE]

I was wandering if there is a easy way to put a button on my page to save only part 1 of my page. but probably the way of sovik is the only way to do something like this.

but it still would be nice when someone could come with a other opinion.
Copy linkTweet thisAlerts:
@konithomimoFeb 08.2007 — the saveAs command will only work in IE. To save a file to the users comp, they must download it, or you must be using something such as a plugin, or java applet, which the user will have to agree to use/install. To save a file to the server you will have to use a server-side language such as PHP.
Copy linkTweet thisAlerts:
@potzetauthorFeb 08.2007 — I think i have to be more clearly with my question.

Part one of the text on my HTML/PHP page have to be Saved on the local machine. (download)

The javasript that i have at the moment saves the whole page to a file om my local machine.

i expact there is something like document.getElementById("text1"); in the code that i'm looking fore.

p.s. thank you konithomimo for your reply
Copy linkTweet thisAlerts:
@konithomimoFeb 08.2007 — I am glad to help, but there are a few problems. The first is that JScript, the MS version of JavaScript can save to a text file on the local machine. The problem with it is that it is a security violation, and many users will not approve of it. The best way to do it is to save the file to a temp file on your server and then create a dynamic link that the user can click on to download it. the saveAs command, is IE only. There is a Mozilla work around to save a text file, but again, it is a sescurity violation and is not suggested.
Copy linkTweet thisAlerts:
@felgallFeb 09.2007 — The document.execCommand("SaveAs") command is a JScript command intended for use on Intranets where you can configure each of the computers to specifically allow that command to run for the local intranet site. It can't be used on the inter net because only IE understands it and it will only run there where the security is set appropriately to allow it wwwhich it wont be if it is in the internet zone.
Copy linkTweet thisAlerts:
@potzetauthorFeb 09.2007 — The best way to do it is to save the file to a temp file on your server and then create a dynamic link that the user can click on to download it. [/QUOTE]

That is realy a great way! thnx i keep it in mind. ?

The problem i have is That Part one of my page is variable. so it is always a differend text.
Copy linkTweet thisAlerts:
@potzetauthorFeb 09.2007 — thnx for the info felgall
×

Success!

Help @potzet spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.23,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...