gpt4 book ai didi

Javascript 查询字符串无法在移动设备上运行

转载 作者:行者123 更新时间:2023-12-03 08:51:59 25 4
gpt4 key购买 nike

<script>// <![CDATA[
$(function(){
var currentPostUrl = window.location.href + "?ref=blogshare"
var currentPostTitle = $('.post-title').text().trim();

$('#myModal').appendTo("body")

var facebookShareUrl = "https://www.facebook.com/sharer/sharer.php?u=" + currentPostUrl
var emailShareUrl = "mailto:?to=&body=Hey, I thought you might like this post. It's called " + currentPostTitle + ". You can read it here: " + currentPostUrl + "&subject=Thought you might like this post..."


$('.email-share').attr('href', emailShareUrl);

// ]]></script>

上述脚本的目标是获取当前 url 并向其附加一个 ref 查询字符串。然后我们更改链接的 href 以添加自定义 mailto。

上面的内容在桌面上似乎运行得很好。但在移动设备(chrome iPhone)上,当我单击电子邮件共享链接时,?ref=blogshare 不会附加到链接中。

有什么想法吗?

最佳答案

您需要对查询字符串值进行编码。

encodeURIComponent()

var currentPostUrl = encodeURIComponent(window.location.href + "?ref=blogshare");

关于Javascript 查询字符串无法在移动设备上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32642126/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com