Lentin
V2EX  ›  分享创造

一个简易的 PC 浏览器同步手机当前打开网页的方案

By Lentin at 2018 年 4 月 22 日 · 5431 次点击
有时候 PC 上浏览了个页面想在手机上打开,但是 PC 的 Chrome 跟手机 Safari 的历史记录没有同步,扫二维码也不是特别方便,我做了个书签,搭配一个 php 使用。

php 源文件如下,只是获取 url 之后写到一个 txt 里面暂存 url
u.php
<?php
header('Access-Control-Allow-Origin:*');
if ($_GET["url"]) {
fwrite(fopen("url.txt","w"),$_GET["url"]);
echo "Success";
} else {
header('Location: '.file_get_contents('url.txt'));
}
?>

Crhome 书签地址如下

javascript:xmlhttp=new XMLHttpRequest();xmlhttp.open("get","https://yourdomain/u.php?url="+window.location.href,true);xmlhttp.send();xmlhttp.onreadystatechange=function(){if (xmlhttp.readyState==4 && xmlhttp.status==200){alert("ok");}}

实现的结果就是流量器上点一下书签,然后手机上访问 https://yourdomain/u.php 就能跳转到你当前标记的网页了。
由于技术不到位,功能简陋,思路大概是这样,有大佬优化一下就更好了……
16 条回复  •  2018-04-22 21:20:06 +08:00
huangtao728
   1
huangtao728  
   2018 年 4 月 22 日 via Android
思路简洁,我觉得不错
ilay1678
   2
ilay1678  
   2018 年 4 月 22 日 via Android
反过来手机浏览的网页同步到电脑呢
summerwar
   3
summerwar  
   2018 年 4 月 22 日
@ifwangs 分享网址到手机 QQ
Lentin
   4
Lentin  
OP
   2018 年 4 月 22 日
@ifwangs 同理,把后面 javascript:书签加到手机……
ctt
   5
ctt  
   2018 年 4 月 22 日
不知咋的有的页面点了书签不会 ok
Chingim
   6
Chingim  
   2018 年 4 月 22 日 via Android
这个需求我一般用 pushbullet
Lentin
   7
Lentin  
OP
   2018 年 4 月 22 日
@ctt F12 查错吧
ctt
   8
ctt  
   2018 年 4 月 22 日
VM125:1 Mixed Content: The page at 'https://www.v2ex.com/t/448807#reply7' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://?url=https://www.v2ex.com/t/448807'. This request has been blocked; the content must be served over HTTPS.

我的网站没 https 的原因
Lentin
   9
Lentin  
OP
   2018 年 4 月 22 日
@ctt 随便找个支持 https 免费空间就行了,也没啥负载
ctt
   10
ctt  
   2018 年 4 月 22 日
没找到啊。。不过小小改动,也凑合用用了
php 的 echo "Success"; 改成 header('Location: '.$_GET["url"]);

书签改成
javascript:window.location.href="http://xxx/?url="+encodeURIComponent(window.location.href)

就是比 https 方案多刷新了下页面
lvsemi1
   11
lvsemi1  
   2018 年 4 月 22 日 via Android
firefox->发送到其他设备
goreliu
   12
goreliu  
   2018 年 4 月 22 日
@ctt 支持 https 的免费空间的话,可以用 coding.net 的 “动态 Pages ”,功能比较弱,只支持 php,不支持访问网络,只有 128 MB 本地空间(每次更新代码都会清空)和 128 MB MySQL 空间。之前一直没想到怎么利用,但用这个倒是可以。
cctv6
   13
cctv6  
   2018 年 4 月 22 日 via iPhone
想法很好
HangoX
   14
HangoX  
   2018 年 4 月 22 日 via Android
默默的用 chrome
Epsil0n9
   15
Epsil0n9  
   2018 年 4 月 22 日
@Chingim 记得以前 pb 上自动同步的短信内容无法手动删除,当时感到非常无语
XnEnokq9vkvVq4
   16
XnEnokq9vkvVq4  
   2018 年 4 月 22 日
作为临时方案很不错
爱意满满的作品展示区。
© 2026 V2EX · 41ms · 3.9.8.5