Why won't mailto include link parameters?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-23 17:38:17

问题


When this code runs the alert box comes up with the link that includes &list=groceries and &email=tim@sitebuilt.net. 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>

回答1:


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;


来源:https://stackoverflow.com/questions/9138171/why-wont-mailto-include-link-parameters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!