使用ExternalInterface和IE从JavaScript获取Flash中的当前URL
我正在尝试获取 Flash 播放器当前所在的 URL。不是 .swf 文件的 URL,而是浏览器指向的 URL。到目前为止我已经使用过:
var st:String = ExternalInterface.call("window.location.href");
不幸的是这在 IE 中不起作用。根据我的研究,我发现它无论如何都不适用于 IE。
我在互联网上发现的唯一的另一件事是在标签上放置一个“id”标签。
所以我试图找出我是否可以和/或如何:
如何在 IE 和其他浏览器中使用外部接口进行调用 浏览器返回给我当前的 网址。
或
在标签上添加 id="PA" 属性并让 AS3 读取该标签 并将其作为字符串拉入,无需 使用 JavaScript
我的限制是我只能将标签添加到 HTML,而不能添加任何 JavaScript 函数。这必须在 AS3 中严格执行。
不管怎样,我需要知道我所在的 URL。非常感谢任何帮助。
I'm trying to get the current URL that the Flash player is on. Not the URL of the .swf file, but the URL that the browser is pointing to. Thus far I've used:
var st:String = ExternalInterface.call("window.location.href");
Unfortunately this doesn't work in IE. From my research, I can see that it won't work with IE either way.
The only other thing I found around the Internet is putting an 'id' tag on the tag.
So I'm trying to find out if and/or how I can:
Somehow make a call using the ExternalInterface in IE and other
browsers to return to me the current
URL.OR
Slap an id="PA" attribute on the tag and have AS3 read that tag
and pull it in as a String, without
using JavaScript
My limitation is that I can ONLY add the tag to the HTML and cannot add any JavaScript functions. This has to be strictly done in AS3.
Either way, I need to know what URL I'm on. Any help is greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
为了使其在 IE 中运行,您需要做一些事情。首先是 ActionScript:
其次,您需要在
如果不添加这些属性,ExternalInterface.call 在 IE6/7/8 中始终返回 null,但在 Firefox 中按预期工作。
第三,您需要将参数allowScriptAccess 设置为“always”,以便启用ExternalInterface。
……
You need a couple of things in order to make it work in IE. First the ActionScript:
Second, you need valid classid and id atributes in the
<object>
tag:If you don't put those attributes, ExternalInterface.call always returns null in IE6/7/8 but works as expected in firefox.
Third, you need to set the param allowScriptAccess to 'always', in order to enable the use of ExternalInterface.
.....
只是一个建议:
这可能是因为 IE 出于某种原因决定 window.location.href 可以用作函数。这很愚蠢,但这就是为你服务的微软。
您是否尝试过ExternalInterface.call(“String”,“window.location.href”)?这将是我的下一个猜测。
Just a suggestion:
That is likely because IE has, for some reason, decided that window.location.href can be used as a function. It is asinine, but that is Microsoft for you.
Have you tried ExternalInterface.call( "String", "window.location.href" )? That would be my next guess.
您是否考虑过在没有外部调用的情况下实现您想要的目标?
上面,我们使用 indexOf 追踪出基本域,以从 swf 的完整路径创建子字符串。我们搜索第 8 个字符后的第一个“/”实例以返回子字符串的结束点。我们使用 8 个字符的原因是为了允许 http:// 和 https://;我们需要它不要看到那些第一个“/”。我对此进行了测试,效果很好。
ExternalInterface 调用没有任何问题,但我倾向于在需要时保存它们。
Have you given any thought to achieving what you want without an External Call.
Above, we trace out the base domain using indexOf to make a sub-string from the full path to the swf. We search for the first instance of "/" after the 8th character to return the end point of the substring. The reason we go in 8 characters is to allow for http:// and https://; we need it not to see those first "/"'s. I tested this and it worked great.
There is nothing wrong with ExternalInterface calls, but I tend to save them for when required.