简体   繁体   English

如何为我的网站创建一个类似“ Digg it”的按钮?

[英]How can I make a button like 'Digg it' for my website?

I've got a blogging site hosted on Windows Sever, ASP.Net 3.5, ASP.Net AJAX, SQL Server in background. 我在Windows Sever,ASP.Net 3.5,ASP.Net AJAX,SQL Server后台托管了一个博客站点。

I want to give bloggers a button like 'digg-it' which they can put on their blogs for the readers to click to thumb-up the post if they like it. 我想给博客作者一个类似'digg-it'的按钮,他们可以在博客上放置这些按钮,以供读者单击(如果愿意)竖起该帖子。

I know I'll be using Javascript to do that. 我知道我将使用Javascript来做到这一点。 What can I do to: - 我该怎么做:-

  1. Retrieve code from my website which will display the current count of the thumb-up. 从我的网站检索代码,该代码将显示当前的大拇指数。
  2. Increase the count on my website if the user thumbs up something. 如果用户竖起大拇指,增加我的网站上的数量。

Since most of these blogs are on blogger.com/wordpress.com, the plugin code will be embedded in the blog theme. 由于这些博客大部分位于blogger.com/wordpress.com上,因此插件代码将嵌入博客主题中。 I guess I will be using the URL of the blog post as the unique id. 我想我将使用博客文章的网址作为唯一ID。 My problem is how to get my site and javascript that's on blogger.com talking. 我的问题是如何让我的网站和blogger.com上的javascript对话。

Your help will be appreciated. 您的帮助将不胜感激。

Thanks 谢谢

You can look into using SCRIPT callbacks loading JSON data instead of using XmlHttpRequest to get around the crossdomain issues. 您可以研究使用SCRIPT回调加载JSON数据,而不是使用XmlHttpRequest来解决跨域问题。

function dynScript(url){
    var script=document.createElement('script');
    script.src=url;
    script.type="text/javascript";
    document.getElementsByTagName('head')[0].appendChild(script);
}
function handleYourData(json) {
    // Do something with your response data if you need to, like alter
    // dom.
}
function thumbUp(postId) {
    dynScript('http://yourdomain.com/path/to/thumbHandler?callback=handleYourData&thumbs=up&postId=' + postId);
}
function thumbDown(postId) {
    dynScript('http://yourdomain.com/path/to/thumbHandler?callback=handleYourData&thumbs=down&postId=' + postId);
}

You can use it like this in your HTML. 您可以在HTML中像这样使用它。

<a onClick="thumbUp(521);">Thumb up</a> | <a onClick="thumbDown(521);">Thumb Down</a>

Your thumbHandler code would have to output JSON with handleYourData() wrapped around it so that your callback will be called with the JSON data as the argument. 您的thumbHandler代码将不得不输出带有handleYourData() JSON,以便您将以JSON数据作为参数来调用您的回调。

Okay, I got one answer and while I was trying that method I found something easier. 好的,我得到了一个答案,当我尝试这种方法时,我发现了一些简单的方法。

What I am going to use is an iframe. 我要使用的是iframe。 An iframe is like a browser window within the browser. iframe就像浏览器中的浏览器窗口一样。 The code I render in the iframe will internally access my website as if it's a regular webpage request. 我在iframe中呈现的代码将在内部访问我的网站,就像是常规网页请求一样。 So I can use my web services, my background ASP.Net code, and generally everything I want without worrying about messing up the host website. 因此,我可以使用我的Web服务,后台ASP.Net代码以及通常所需的所有内容,而不必担心搞乱主机网站。

When I am done developing, I'll post some code here. 完成开发后,我将在此处发布一些代码。 Meanwhile if you guys know of any pitfall in this approach please tell me. 同时,如果你们知道这种方法有什么陷阱,请告诉我。

Here's some sample iframe code that I wrote 这是我编写的一些示例iframe代码

<script type="text/javascript">
    window.onload = function() {
        alert("http://mysite.com?url=" + window.location.href);
        document.all.blogvaniframe.src = "http://blogvani.com";
    }
</script>
<iframe id="blogvaniframe" height="100" width="100" scrolling="no" frameborder="0">

</iframe>

I am using javascript to load the content in the iframe because I want to pass an argument to the url's querystring (haven't tested this yet though. 我使用javascript在iframe中加载内容,因为我想将参数传递给url的querystring(尽管尚未对此进行测试。

Thanks 谢谢

Try this one. 试试这个。 I found it on Yahoo! 我在Yahoo!上找到了它! Search because I knew, there was a German version of this script: 搜索,因为我知道此脚本有德语版本:

English version: http://www.socialbookmarkscript.com/ 英文版: http//www.socialbookmarkscript.com/

German script: http://www.social-bookmark-script.de/ 德语脚本: http : //www.social-bookmark-script.de/

Good luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM