Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/75.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函数的自定义URL?_Javascript_Html_Ajax_Social_Sharethis - Fatal编程技术网

如何动态创建;“共享此按钮”;使用带有javascript函数的自定义URL?

如何动态创建;“共享此按钮”;使用带有javascript函数的自定义URL?,javascript,html,ajax,social,sharethis,Javascript,Html,Ajax,Social,Sharethis,我用按钮给网站上的用户提供了一种简单的分享内容的方式 他们在这里有关于“自定义按钮”的信息: 它看起来像是指定URL,在示例中,它们都有如下html: <span class="st_sharethis" st_url="http://mycustomurl.com" st_title="Sharing Rocks!" displayText="ShareThis"></span> 有没有人能举一个例子,说明我如何在不重新加载页面的情况下做到这一点 编辑: @立方 弹出

我用按钮给网站上的用户提供了一种简单的分享内容的方式

他们在这里有关于“自定义按钮”的信息:

它看起来像是指定URL,在示例中,它们都有如下html:

<span class="st_sharethis" st_url="http://mycustomurl.com" st_title="Sharing Rocks!"
displayText="ShareThis"></span>
有没有人能举一个例子,说明我如何在不重新加载页面的情况下做到这一点

编辑: @立方

弹出窗口出现

但是如果我在函数中有上面的setAttribute代码,弹出窗口就不会出现,所以我假设代码中有什么东西破坏了它。有什么建议吗?或者至少我可以用chrome告诉我错误是什么?我尝试了inspect元素控制台,但当我触发该功能时,那里没有显示任何内容

此外,在我的代码顶部,他们让我使用:

    <script type="text/javascript">var switchTo5x=true;</script>
<script type="text/javascript" src="http://w.sharethis.com/button/buttons.js">
</script><script type="text/javascript">stLight.options({publisher:'mypubidgoeshere'});</script>
var switchTo5x=true;
选项({publisher:'myPubidGoesher'});
我应该用吗
stLight.locateElements()而不是
stButtons.locateElements()

我一直在使用

stButtons.locateElements();
函数在通过AJAX加载内容后生成任何新按钮,我想它也适用于此

这个问题可能也会有所帮助:

更好的解决方案:

确保你的
并确保所有
都有ID,否则你可以给它们类,但你需要遍历它们

function shareChannel(theurl, thetitle)
    {
    document.getElementById('spanID1').setAttribute('st_url', theurl);
    document.getElementById('spanID1').setAttribute('st_title', thetitle);

    stButtons.locateElements();

    //finally display the popup after the buttons are made and setup.
    displaypopup();
    }

所以,你是说我只需要在html中创建span类…然后我可以在flash触发的函数中执行…只需使用
stButtons.locateElements()
在运行函数时以某种方式更改URL/标题?您能告诉我如何使用它来更改url/标题吗?对不起,我对actionsctipt很在行。对javascript和ajax非常陌生。很抱歉这就是你的目的吗?有点粗糙。太棒了,这是有道理的。这看起来正是我想要做的…但是经过测试它根本不起作用。我在上面发布了一些信息。介意快速看一下编辑吗?谢谢!代码中有一个输入错误,你有“chann”和“chaan”,这就是为什么它不起作用,将标题“chann”改为“chaan”,它应该会产生奇迹。为了记录,chrome中的Tools>Javascript控制台将让您进入调试器。如果您在更改之前到达该位置,它应该有一个错误“UncaughtReferenceError:chann未定义”
    <script type="text/javascript">var switchTo5x=true;</script>
<script type="text/javascript" src="http://w.sharethis.com/button/buttons.js">
</script><script type="text/javascript">stLight.options({publisher:'mypubidgoeshere'});</script>
stButtons.locateElements();
function shareChannel(theurl, thetitle)
    {
    document.getElementById('spanID1').setAttribute('st_url', theurl);
    document.getElementById('spanID1').setAttribute('st_title', thetitle);

    stButtons.locateElements();

    //finally display the popup after the buttons are made and setup.
    displaypopup();
    }