为什么 mailto 不包含链接参数?

发布于 2025-01-01 23:16:02 字数 2079 浏览 0 评论 0原文

当此代码运行时,警报框会显示包含 &list=groceries 和 &[电子邮件受保护]。当 mailto: 触发并打开电子邮件窗口时,这些参数丢失,我不明白为什么。字符串的长度似乎并不重要。

该代码具有运行所需的一切。您可以在此处运行它: http://jsfiddle.net/mckennatim/rRerR/

        <div data-role="header">
            <h1>My Title</h1>
        </div><!-- /header -->       
        <div data-role="content">   
            <h3>Add List</h3> 
            <form>
                <div data-role="controlgroup"  id="addwhat">
                    <input type="email"  id="shemail" name="inp0" class="inp" />
                </div>  
                <div data-role="controlgroup" data-type="horizontal" class="aisubmit">
                    <input type="submit" data-theme="b" id="mailit" value="mail it"/>
                </div>                          
             </form> 
        </div><!-- /content -->
    </div><!-- /page -->
    <script>
        $('body').on('click', "#mailit", function (e) { 
            e.stopImmediatePropagation();
            e.preventDefault();
            repo = "Sebaza";
            list = "groceries";
            semail = $("#shemail").val();
            //(semail);
            urri ='mailto:'+ semail  + '?subject=share this list with me' + '&cc=' + semail + '&body=Hi, I think it would be cool if we shared this ' + list +' list on our phones. That way when either of us modified it we would see the update. http://10.0.1.18/webeshoppin/stuff2get/www/food2buy.html?repo=' + repo + '&list=' + list + '&email=' + semail  ;
            window.location = urri;
            alert('clicked ashare ' +urri);   
        });          
    </script>    
</body>
</html>

When this code runs the alert box comes up with the link that includes &list=groceries and &[email protected]. When the mailto: fires and brings up the email window those parameters are missing and I can't figure out why. the length of the string doesn't seem to matter.

This code has all it needs to run. You can run it here: http://jsfiddle.net/mckennatim/rRerR/

        <div data-role="header">
            <h1>My Title</h1>
        </div><!-- /header -->       
        <div data-role="content">   
            <h3>Add List</h3> 
            <form>
                <div data-role="controlgroup"  id="addwhat">
                    <input type="email"  id="shemail" name="inp0" class="inp" />
                </div>  
                <div data-role="controlgroup" data-type="horizontal" class="aisubmit">
                    <input type="submit" data-theme="b" id="mailit" value="mail it"/>
                </div>                          
             </form> 
        </div><!-- /content -->
    </div><!-- /page -->
    <script>
        $('body').on('click', "#mailit", function (e) { 
            e.stopImmediatePropagation();
            e.preventDefault();
            repo = "Sebaza";
            list = "groceries";
            semail = $("#shemail").val();
            //(semail);
            urri ='mailto:'+ semail  + '?subject=share this list with me' + '&cc=' + semail + '&body=Hi, I think it would be cool if we shared this ' + list +' list on our phones. That way when either of us modified it we would see the update. http://10.0.1.18/webeshoppin/stuff2get/www/food2buy.html?repo=' + repo + '&list=' + list + '&email=' + semail  ;
            window.location = urri;
            alert('clicked ashare ' +urri);   
        });          
    </script>    
</body>
</html>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

謸气贵蔟 2025-01-08 23:16:02

这 '?'和“&” mailto 链接的解析器正在删除字符。

这些字符需要进行编码。尝试替换为:

? = %3F
& = %26

所以,JS 行将如下所示:

urri ='mailto:'+ semail  + '?subject=share this list with me' + '&cc=' + semail + '&body=Hi, I think it would be cool if we shared this ' + list +' list on our phones. That way when either of us modified it we would see the update. http://10.0.1.18/webeshoppin/stuff2get/www/food2buy.html%3Frepo=' + repo + '%26list=' + list + '%26email=' + semail;

The '?' and '&' characters are being stripped out by the parser of the mailto link.

Those characters need to be encoded. Try replacing with:

? = %3F
& = %26

so, that JS line would look like:

urri ='mailto:'+ semail  + '?subject=share this list with me' + '&cc=' + semail + '&body=Hi, I think it would be cool if we shared this ' + list +' list on our phones. That way when either of us modified it we would see the update. http://10.0.1.18/webeshoppin/stuff2get/www/food2buy.html%3Frepo=' + repo + '%26list=' + list + '%26email=' + semail;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文