来自 Actionscript 3 应用程序的 Twitter Intent 弹出窗口
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看 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 页面;例如:
然后您可以通过ExternalInterface调用从ActionScript项目中调用它,正如您之前所建议的:
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:
You can then invoke this from your ActionScript project via an ExternalInterface call, as you previously suggested: