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>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值