来自 Actionscript 3 应用程序的 Twitter Intent 弹出窗口

发布于 2024-11-27 12:15:04 字数 603 浏览 1 评论 0原文

我有一个 AS3 应用程序,可以向用户显示推文。我正在尝试使用 twitter 意图链接来执行弹出窗口,例如 https://twitter.com /intent/retweet?tweet_id=93035636432437248

当您有一个简单的 href="link" 时,它将使用嵌入的 http://platform.twitter.com/ widgets.js 正确格式化一个漂亮的弹出窗口。

在 Flash 中时,我只能以 self 或空白打开,并且不会像单击 html href 链接时那样触发 JavaScript。

我还尝试使用ExternalInterface调用js方法来使用document.location或window.open,但都没有使用twitter js。

从 Flash 按钮利用 Twitter JavaScript 以便获得漂亮干净的弹出窗口的最佳方法是什么?

I have an AS3 application that shows users tweets. I'm trying to use the twitter intents links to do popups, such as https://twitter.com/intent/retweet?tweet_id=93035636432437248.

When you have a simple href="link" it will use the embedded http://platform.twitter.com/widgets.js to properly format a nice popup window.

When in flash I can only open in self or blank and neither triggers the JavaScript the same way it does when you click from html href links.

I also tried using ExternalInterface to call a js method to use document.location or window.open and neither used the twitter js.

What is the best way to harness the Twitter JavaScript from a flash button so we get the nice clean popup window?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

对岸观火 2024-12-04 12:15:04

查看 Twitter Web Intents API 文档,在页面底部附近,您可以找到指向未混淆的源代码显示了他们的 API 如何自动处理链接。

简而言之,他们将 Click 事件处理程序附加到 DOM,然后检查被单击的链接是否指向其 Web Intents URL。当您从 ActionScript 打开窗口时,您将绕过 DOM,因此代码不会触发。

现在通常您只希望使用ExternalInterface 来调用Web Intents API 公开的方法;然而,Twitter 的聪明人已经在匿名闭包中创建了他们的整个 API,以避免污染 DOM - 一定喜欢 javascript;)

因此,就我个人而言,我会通过创建我自己的 Twitter Web Intents API 版本并将其包含在我的 Flash 应用程序所在的 HTML 页面;例如:

// Create a global object which we can attach methods to.
var TwitterAPI = {};

// The methods themselves are created in a closure to avoid polluting the global
// namespace with temporary variables.
(function() {
    // The base URL of the Twitter API.
    TwitterAPI.baseURL = "https://twitter.com/intent/";

    // Opens a pop-up window and prompts the user to retweet the Tweet linked to 
    // the supplied tweet_id.
    TwitterAPI.retweet = function(tweet_id) {
        var url = TwitterAPI.baseURL + "retweet?tweet_id=" + tweet_id;
        openWindow(url);
    }

    function openWindow(url) {
        var windowOptions = "scrollbars=yes,resizable=yes,toolbar=no,location=yes";
        var width = 550;
        var height = 420;

        // Center the popup window.
        var left = Math.round((screen.width / 2) - (width / 2));
        var top = 0;        
        if (screen.height > height) {
                top = Math.round((screen.height / 2) - (height / 2));
            }

        window.open(url, 'intent', windowOptions + ",width=" + width +
            ",height=" + height + ",left=" + left + ",top=" + top);

    }
}());

然后您可以通过ExternalInterface调用从ActionScript项目中调用它,正如您之前所建议的:

ExternalInterface.call("TwitterAPI.retweet", "35782000644194304");

Looking at the Twitter Web Intents API Documentation, near the bottom of the page you can find a link to the unobfuscated source code which shows how their API automatically handles links.

Put simply they are attaching a Click Event Handler to the DOM which then checks to see if the link being clicked points to their Web Intents URL. As you are opening a window from ActionScript you are bypassing the DOM and therefore the code won't fire.

Now normally you would just expect to use ExternalInterface to call a method exposed by the Web Intents API; however the clever chaps at Twitter have created their entire API in an anonymous closure to avoid polluting the DOM - gotta love javascript ;)

So, personally, I would tackle this by creating my own version of the Twitter Web Intents API and including it on the HTML page which my Flash Application sits; for example:

// Create a global object which we can attach methods to.
var TwitterAPI = {};

// The methods themselves are created in a closure to avoid polluting the global
// namespace with temporary variables.
(function() {
    // The base URL of the Twitter API.
    TwitterAPI.baseURL = "https://twitter.com/intent/";

    // Opens a pop-up window and prompts the user to retweet the Tweet linked to 
    // the supplied tweet_id.
    TwitterAPI.retweet = function(tweet_id) {
        var url = TwitterAPI.baseURL + "retweet?tweet_id=" + tweet_id;
        openWindow(url);
    }

    function openWindow(url) {
        var windowOptions = "scrollbars=yes,resizable=yes,toolbar=no,location=yes";
        var width = 550;
        var height = 420;

        // Center the popup window.
        var left = Math.round((screen.width / 2) - (width / 2));
        var top = 0;        
        if (screen.height > height) {
                top = Math.round((screen.height / 2) - (height / 2));
            }

        window.open(url, 'intent', windowOptions + ",width=" + width +
            ",height=" + height + ",left=" + left + ",top=" + top);

    }
}());

You can then invoke this from your ActionScript project via an ExternalInterface call, as you previously suggested:

ExternalInterface.call("TwitterAPI.retweet", "35782000644194304");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文