Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Save a copy of current page on server? 2

Status
Not open for further replies.

mandiana

Programmer
Sep 6, 2008
6
0
0
US
Is it possible with javascript to save the html source code of the page that is currently being viewed by the user to the server?
 
With AJAX, I think so. But why would you want to do that? The only decent reason I can think of is if the page has been changed by some previous AJAX calls. Otherwise you could save the source code before it is sent to the browser.

-----------------------------------------
I cannot be bought. Find leasing information at
 
Thank you for your response jaxtell. Could you point me in the right direction where I could learn about doing this with AJAX? Sorry, I'm very new to javascript and ajax.

I would love to have thought about saving the source code before I sent it to the browser before these dozens, maybe hundreds, of scripts I am working with were created, but I didn't. If I were using php, I could use ob_start(), but I'm using Perl and I don't know of a perl equivalent. All of these perl scripts are thankfully using common headers and footers so one good piece of javascript or ajax would be a lifesaver.

My purpose in doing so is to have a copy of what exactly visitors are seeing when going around the site so I can see what makes people stay and what makes people leave.

Thanks again,
~Amanda
 
I'm a bit off topic now, but I think this might be the right solution for you.
This is from
Re-opening STDOUT

It is quite permissible to re-open existing filehandles. When you do, the filehandle is first closed, and the new one is opened. This works with STDOUT too. You can re-open STDOUT, and then use the print statement to write to your new file by default.

open STDOUT, ">output.txt";
print "The quick brown fox\n";
close STDOUT;
I'm not sure if you can specify more than one output. If you could, then you can create your file and send the html to the browser. If not, create the file, change STDOUT again, then read the file and send it to the browser. My javascript is weak, so I stick with what I know. I hope this helps.

-----------------------------------------
I cannot be bought. Find leasing information at
 
Hi

Your requirement remembered my TiddlyWiki. That is plain JavaScript and saves the edited wiki ( in fact a modified copy of the viewed document itself ) to the local machine. It could give you some starting ideas.

Anyway, I do not suggest to do it. Learn [tt]perl[/tt].

Feherke.
 
jaxtell,

You're right. We are getting seriously off topic, but you have me so close! Based on what you suggested, I've come up with the following.

"The quick brown fox\n" is printing to the file fine, but it's not printing to the screen. Is it possible to make $line print to the screen too? It's driving me crazy because I can print $line to a LOG file, but I can't figure out how to print it to the browser too. Grrr.

####################################
print "Content-type: text/html\n\n";
$file = "yah.html";
open (STDOUT, ">$file");
print "The quick brown fox\n";

close (STDOUT);

open (FILE, "$file");

@data = <FILE>;

close (FILE);
foreach $line(@data){

print $line;

}
exit;
####################################

Thanks again,
~Amanda
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top