如何动态地创建"分享这个按钮"与javascript函数的自定义网址?自定义、函数、按钮、网址

2023-09-10 13:41:55 作者:浪痞.

使用 http://sharethis.com/ 按钮给一个网站的用户一个简单的方法来共享内容的IM。

im using the http://sharethis.com/ buttons to give users on a website a simple way to share content.

他们的自定义按钮这里的信息:http://help.sharethis.com/customization/custom-buttons

They have information on "custom buttons" here: http://help.sharethis.com/customization/custom-buttons

它看起来像到指定的URL,在这个例子中曾经拥有它只是HTML这样的:

It looks like to specify the URL, in the example all they have its just html like this:

<span class="st_sharethis" st_url="http://mycustomurl.com" st_title="Sharing Rocks!"
displayText="ShareThis"></span>

不过,我需要能够动态地动态创建按钮无需重新加载页面。

But I need to be able to dynamically create buttons on the fly without reloading the page.

所以,在Flash应用程序我建立我有一个分享按钮触发一个JavaScript函数,使一个弹出分区消失在画面,我想要显示的共享按钮中心的网页。根据什么分享按钮有人点击它需要有一个动态创建的URL。

So, In a flash application i'm building i have a "share button" that triggers a javascript function on the webpage that makes a "popup" div fade into the center of the screen that I want to display the share buttons. Depending on what share button someone clicks it will need to have a dynamically created URL.

这一点很重要,如果他们关闭对话框,然后再次点击分享按钮,即时通讯希望在code只是简单地覆盖旧的code与新的按钮,新的URL /标题。

It's important if they close the dialog, then click the share button again, im hoping the code will just overwrite the old code with new buttons, with the new url/titles.

所以,我创建了我从闪存中调用这个javascript函数,同时通过链接从闪存。我把剧本,一切都在我的弹出分区,希望这些按钮将是DIV中呈现。

So, i created this javascript function that I call from flash, while passing the url from flash. I placed the script and everything inside my "popup" div, hoping that the buttons will be rendered inside that div.

function shareChannel(theurl)
{
//I cant seem to find an example of what to put here to load the buttons, and give them a custom URL and title

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

可能有人可能发布的我怎么可能能够做到这一点的一个例子而没有重新加载页面?

could anyone possibly post an example of how I might be able to do this without ever reloading the page?

编辑: @Cubed

@Cubed

<script type="text/javascript">
function shareChannel(chaan)
          {

          document.getElementById('spID1').setAttribute('st_url', 'http://mycustomurl?chan='+chaan);
          document.getElementById('spID1').setAttribute('st_title', 'Custom Title is ['+chann+'] it works!');

          stButtons.locateElements();

          centerPopupThree();
          loadPopupThree();
          }

</script>

基本上没有任何反应。我讨厌使用JavaScript,因为我真的不知道如何获得错误信息或调试。当我使用Flex的工作,我有一个伟大的调试器/控制台messaround用。因此,有提供更多信息的麻烦遗憾的IM。我也注意到,当我刚刚删除了

Basically nothing happens. I hate using javascript because I really have no idea how to get error messages or debug. When I work with flex, I have a great debugger/console to messaround with. So, sorry im having trouble providing more info. I did notice when I remove just the

document.getElementById('spID1').setAttribute('st_url', 'http://mycustomurl?chan='+chaan);
              document.getElementById('spID1').setAttribute('st_title', 'Custom Title is ['+chann+'] it works!');

在弹出窗口。

The popup appears.

但是,如果我有以上的setAttribute code函数内部,在弹出永远不会出现,因此即时假设的东西在code为打破它。有什么建议么?或者至少是一个方法,我可以使用Chrome来告诉我的错误是什么?我试过检查的元素控制台,但没有什么是出现在那里,当我触发功能。

But if I have the above setAttribute code inside the function, the popup never appears, so im assuming something in that code is breaking it. Any suggestions? Or at least a way I could use chrome to tell me what the error is? I tried the inspect element console but there was nothing that appeared there when i triggered the function.

此外,在我的code上他们有我使用的:

Also, in at the top of my code they had me use:

    <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>

我应该使用 stLight.locateElements(); ,而不是 stButtons.locateElements();

Should I be using stLight.locateElements(); rather than stButtons.locateElements();

推荐答案

我一直在使用

stButtons.locateElements();

功能通过AJAX加载的内容后,我想它会为这个产生任何新的按钮了。

function to generate any new buttons after loading content via AJAX, I imagine it will work for this too.

此问题可能是一些援助也是:

This question might be of some assistance also:

Sharethis按钮不会在通过AJAX

更好的解决方案:

请您&LT; D​​IV&GT; ,并确保所有的&LT;跨度&GT; 活动的标识,否则你可以给他们班,但你会需要遍历所有。

Make your <div> and make sure all the <span>s have IDs, otherwise you can give them classes but you will need to iterate through them all.

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();
    }