Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 是否可以将本地存储值加载到tweet中?_Javascript_Jquery_Twitter_Local Storage - Fatal编程技术网

Javascript 是否可以将本地存储值加载到tweet中?

Javascript 是否可以将本地存储值加载到tweet中?,javascript,jquery,twitter,local-storage,Javascript,Jquery,Twitter,Local Storage,如果我正在使用JS创建一个新的窗口/tweet来共享,我也可以从本地存储中提取信息吗 <li class="fa fa-twitter" onclick="window.open('https://twitter.com/intent/tweet?text=I just score X on this game!', 'newwindow', 'width=300, height=250')"></li>

如果我正在使用JS创建一个新的窗口/tweet来共享,我也可以从本地存储中提取信息吗

<li class="fa fa-twitter" onclick="window.open('https://twitter.com/intent/tweet?text=I just score X on this game!', 'newwindow', 'width=300, height=250')"></li>
  • 我们目前将用户的分数存储在LocalStorage中,其值为
    score
    。我们甚至把它打印在页面上。会不会有人把它上传到推特上

    到目前为止,我已经尝试使用一个跨度,并附加分数,但这会破坏URL


    有什么想法吗

    您可以使用连接添加该值:

    <li class="fa fa-twitter" onclick="window.open('https://twitter.com/intent/tweet?text=I just score ' + localStorage['score'] + ' on this game!', 'newwindow', 'width=300, height=250')"></li>
    
  • 内联js很糟糕:)

    试试这个

    <li class="fa fa-twitter" onclick="onClick"></li>
    
    function onClick(){
       var val = localStorage.get('something');
       window.open("https://twitter.com/intent/tweet?text=I just score X on this"+val+" game!',
       'newwindow',
       'width=300,height=250')
    }
    
  • 函数onClick(){ var val=localStorage.get('something'); 窗口打开(“https://twitter.com/intent/tweet?text=I 在这个“+val+”游戏中只需得分X!”, “新窗口”, '宽度=300,高度=250') }
    是的,您肯定可以这样做。我不会为此使用inline
    onclick
    属性。只需添加事件侦听器,然后您就可以从
    localStorage
    打开带有用户分数的窗口,以及您的文本

    <li class="fa fa-twitter" id="tweet"></li>
    <script>
    $('#tweet').on('click', function(e){
        var score = localStorage.getItem('userScore');
        var tweetTxt = 'I just scored ' + score  + ' on this game!';
        window.open('https://twitter.com/intent/tweet?text='+encodeURIComponent(tweetTxt), 'newwindow', 'width=300, height=250')
    });
    </script>
    
  • $('tweet')。在('click',函数(e)上{ var score=localStorage.getItem('userScore'); var tweetTxt='我刚刚在这场比赛中得分'+得分+''; 打开窗户https://twitter.com/intent/tweet?text=“+encodeURIComponent(tweetTxt),“newwindow”,“宽度=300,高度=250”) });
    保持事情的清晰和简单

    tweetScore=函数(){
    var score=localStorage.getItem('score');
    var text='我刚刚在这个游戏中得分'+score+'!';
    /*变量选项=
    {宽度:300;高度:200,…}
    */
    var url='1〕https://twitter.com/intent/tweet?text=“+文本;
    打开(url,'newwindow','width=300,height=200');
    //或者从选项中获取它们
    返回0;
    }
  • 推特
  • 坏掉的URL是什么样子的?可能是注入字符串时出现了一些URL转义问题对不起,尝试接受此消息,但后来它说这样就停止了维护。这修复了我的问题!非常感谢!