V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
爱意满满的作品展示区。
Lentin

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

  •  
  •   Lentin · Apr 22, 2018 · 5054 views
    This topic created in 2927 days ago, the information mentioned may be changed or developed.
    有时候 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 replies    2018-04-22 21:20:06 +08:00
    huangtao728
        1
    huangtao728  
       Apr 22, 2018 via Android
    思路简洁,我觉得不错
    ilay1678
        2
    ilay1678  
       Apr 22, 2018 via Android
    反过来手机浏览的网页同步到电脑呢
    summerwar
        3
    summerwar  
       Apr 22, 2018
    @ifwangs 分享网址到手机 QQ
    Lentin
        4
    Lentin  
    OP
       Apr 22, 2018
    @ifwangs 同理,把后面 javascript:书签加到手机……
    ctt
        5
    ctt  
       Apr 22, 2018
    不知咋的有的页面点了书签不会 ok
    Chingim
        6
    Chingim  
       Apr 22, 2018 via Android
    这个需求我一般用 pushbullet
    Lentin
        7
    Lentin  
    OP
       Apr 22, 2018
    @ctt F12 查错吧
    ctt
        8
    ctt  
       Apr 22, 2018
    VM125:1 Mixed Content: The page at 'https://www.0.51bbc.workers.dev/t/448807#reply7' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://?url=https://www.0.51bbc.workers.dev/t/448807'. This request has been blocked; the content must be served over HTTPS.

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

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

    就是比 https 方案多刷新了下页面
    lvsemi1
        11
    lvsemi1  
       Apr 22, 2018 via Android
    firefox->发送到其他设备
    goreliu
        12
    goreliu  
       Apr 22, 2018
    @ctt 支持 https 的免费空间的话,可以用 coding.net 的 “动态 Pages ”,功能比较弱,只支持 php,不支持访问网络,只有 128 MB 本地空间(每次更新代码都会清空)和 128 MB MySQL 空间。之前一直没想到怎么利用,但用这个倒是可以。
    cctv6
        13
    cctv6  
       Apr 22, 2018 via iPhone
    想法很好
    HangoX
        14
    HangoX  
       Apr 22, 2018 via Android
    默默的用 chrome
    Epsil0n9
        15
    Epsil0n9  
       Apr 22, 2018
    @Chingim 记得以前 pb 上自动同步的短信内容无法手动删除,当时感到非常无语
    XnEnokq9vkvVq4
        16
    XnEnokq9vkvVq4  
       Apr 22, 2018
    作为临时方案很不错
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3374 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 53ms · UTC 12:55 · PVG 20:55 · LAX 05:55 · JFK 08:55
    ♥ Do have faith in what you're doing.