使用ExternalInterface和IE从JavaScript获取Flash中的当前URL

发布于 2024-08-05 15:07:53 字数 601 浏览 2 评论 0原文

我正在尝试获取 Flash 播放器当前所在的 URL。不是 .swf 文件的 URL,而是浏览器指向的 URL。到目前为止我已经使用过:

var st:String = ExternalInterface.call("window.location.href");

不幸的是这在 IE 中不起作用。根据我的研究,我发现它无论如何都不适用于 IE。

我在互联网上发现的唯一的另一件事是在标签上放置一个“id”标签。

所以我试图找出我是否可以和/或如何:

  1. 如何在 IE 和其他浏览器中使用外部接口进行调用 浏览器返回给我当前的 网址。

  2. 在标签上添加 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:

  1. Somehow make a call using the ExternalInterface in IE and other
    browsers to return to me the current
    URL.

    OR

  2. 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 技术交流群。

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

发布评论

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

评论(4

诠释孤独 2024-08-12 15:07:53

为了使其在 IE 中运行,您需要做一些事情。首先是 ActionScript:

var domain:String = ExternalInterface.call('function () { return window.location.href; }');

其次,您需要在 标记中提供有效的 classid 和 id 属性:

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="myplayer_123123" ...>

如果不添加这些属性,ExternalInterface.call 在 IE6/7/8 中始终返回 null,但在 Firefox 中按预期工作。

第三,您需要将参数allowScriptAccess 设置为“always”,以便启用ExternalInterface。

<param name='allowScriptAccess' value='always'/>
..
<embed allowscriptaccess='always' ...>

……

You need a couple of things in order to make it work in IE. First the ActionScript:

var domain:String = ExternalInterface.call('function () { return window.location.href; }');

Second, you need valid classid and id atributes in the <object> tag:

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="myplayer_123123" ...>

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.

<param name='allowScriptAccess' value='always'/>
..
<embed allowscriptaccess='always' ...>

.....

霊感 2024-08-12 15:07:53

只是一个建议:

这可能是因为 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.

终难愈 2024-08-12 15:07:53
ExternalInterface.call('window.location.href.toString');
ExternalInterface.call('window.location.href.toString');
甜警司 2024-08-12 15:07:53

您是否考虑过在没有外部调用的情况下实现您想要的目标?

var domain:String = loaderInfo.loaderURL;
trace(domain.substr(0, domain.indexOf("/", 8))); //Searches for first instance of "/" after the 8th character.

上面,我们使用 indexOf 追踪出基本域,以从 swf 的完整路径创建子字符串。我们搜索第 8 个字符后的第一个“/”实例以返回子字符串的结束点。我们使用 8 个字符的原因是为了允许 http:// 和 https://;我们需要它不要看到那些第一个“/”。我对此进行了测试,效果很好。

ExternalInterface 调用没有任何问题,但我倾向于在需要时保存它们。

Have you given any thought to achieving what you want without an External Call.

var domain:String = loaderInfo.loaderURL;
trace(domain.substr(0, domain.indexOf("/", 8))); //Searches for first instance of "/" after the 8th character.

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.

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