How to save content/text of a web page by forcing save-as option

I would like to know what would be the best way to save contents from a web page. I mean to force save-as option by clicking a link or button. I often found that javascript would not be an option because it‘s only working for IE, so I thought that it would
be easier because javascript is client-side based.

Now, I thought maybe there is a way to use php when creating a form that will redirect it over a server site query to return and force the save-as option. My main goal is make it possible to save the privacy terms. I would like to avoid using fpdf. If there
is someone who could tell how to solve this I would really appreciate it.

UPDATE:

okay to explain what i like to reach:

imagine you have a simple webpage with some privacy policy text and nothing else. at the top of the page you have two options. first will be print option like:

<a href="javascript:print()">print</a>

second should be something like:

<a href="javascript:saveas()">save</a>

so that when you will press the link the save-as dialog pops up and you can download the content or even page to get the privacy policy for your own.

hope it will be clear now. sorry.

If you want to force a download without javascript, simply open the content in a new tab by adding an unknown target.

Example Code

<a href="whatever.com/download.zip" target="_new">click me</a>

This works only if the page you call offers a download, otherwise the content gets displayed. In this case, you need a simple php-file, which gets the content from the page and customizes the header.

<?php
$content = file_get_contents($_GET["downloadurl"]);
header("Content-Type: application/octet-stream");
echo $content;
?>


UPDATE

As a more detailed example for your edited informations, you could probably do this:

PHP-File "reader.php"

<?php
$content = file_get_contents($_GET["downloadurl"]);
header("Content-Type: application/octet-stream");
echo $content;
?>

HTML on page "test.html"

<a href="reader.php?downloadurl=http://yourwebsite.com/test.html" target="_new">Save website</a>

How to save content/text of a web page by forcing save-as option

时间: 2024-08-26 18:44:14

How to save content/text of a web page by forcing save-as option的相关文章

Using text search in Web page with Sikuli

在網頁中如何使用Sikuli找特定字串呢? 原理: 我們可以使用 組合鍵 ctrl + 來放大網頁的比例,使得sikuli的OCR功能找的更清準 實作: for i in range(4): type("+", KEY_CTRL) which = input() # Let user type the string which user want. print Region(344,178,124,501).hover(which) mouseMove(Env.getMouseLoca

转 :meta name的含义:&lt;META http-equiv=Content-Type content=&quot;text/html; charset=gb2312&quot;&gt;

meta是什么?meta其实是html语言head区的一个辅助性标签.在几乎所有的网页里,我们都可以看到类似下面这段html代码:<META http-equiv=Content-Type content="text/html; charset=gb2312"> 有人要说,这段代码好象可有可无,没有多大实际作用嘛!其实不是没用,而是你没有用好meta标签.为什么这样说呢?这是因为meta标签有许多参数,使用不同的参数就可以使主页实现不同的功能,例如用于鉴别作者,设定页面格式

&lt;META http-equiv=Content-Type content="text/html; charset=gb2312"&gt;

META,网页Html语言里Head区重要标签之一 HTTP-EQUIV类似于HTTP的头部协议,它回应给浏览器一些有用的信息,以帮助正确和精确地显示网页内容.常用的HTTP-EQUIV类型有: 1.Content-Type和Content-Language (显示字符集的设定) 说明:设定页面使用的字符集,用以说明主页制作所使用的文字已经语言,浏览器会根据此来调用相应的字符集显示page内容. <Meta http-equiv="Content-Type" Content=&q

HTML——&lt;meta http-equiv=&quot;content-type&quot; content=&quot;text/html; charset=UTF-8&quot;&gt;

没有添加这句话的编码方式的话,很容易就乱码了 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>search.html</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8&quo

关于&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html:charset=UTF-8&quot;&gt;简单说说

meta是html的元标签,其中包含了对应html的相关信息,客户端浏览器或服务端程序都会根据这些信息进行处理.我们以<meta http-equiv="Content-Type" content="text/html:charset=UTF-8">为例子来说明:http类型:这个网页是表现内容用的content(内容类型):这个网页的格式是文本的charset(编码):这个网页的编码是UTF-8,需要注意的是这个是网页内容的编码,而不是文件本身的.编码

【HTML】明明加了&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;却还是乱码的可能原因

按理说,右键新建一个文本文档,并且把"新建文本文档.txt"改名成"1.html", 然后再于里面写入: <html> <head> </head> <body> 中文 </body> </html> 是一点问题没都没有了的, 可是,部分浏览器打开这个1.html却发现乱码,或者里面的表单传递值的时候发现,你为了不乱码,你就在<head></head>标签中加入 <

save a web page as a single file (mht format) using Delphi code

Here's how to save a web page as a single file (mht format) using Delphi code: uses CDO_TLB, ADODB_TLB;...PRocedure WB_SaveAs_MHT(WB: TWebBrowser; FileName: TFileName);var Msg: IMessage; Conf: IConfiguration; Stream: _Stream; URL : widestring;begin i

Lesson 2 Building your first web page: Part 3

Time to build your first HTML page by hand I could go on with more theory and send half of you to sleep (trust me); instead you are now going to actually build your very first web page! One of the best ways to learn something is to actually do it, so

[Project] Simulate HTTP Post Request to obtain data from Web Page by using Python Scrapy Framework

1. Background Though it's always difficult to give child a perfect name, parent never give up trying. One of my friends met a problem now. his baby girl just came to the world, he want to make a perfect name for her. he found a web page, in which he