使用 ExternalInterface 和 IE 从 JavaScript 获取 Flash 中的当前 URL [英] Getting current URL in Flash from JavaScript using ExternalInterface and IE

查看:32
本文介绍了使用 ExternalInterface 和 IE 从 JavaScript 获取 Flash 中的当前 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

不幸的是,这在 IE 中不起作用.根据我的研究,我可以看到它无论如何都不能与 IE 一起使用.

我在 Internet 上唯一发现的另一件事是在标签上放置一个id"标签.

所以我想知道我是否可以和/或如何:

<块引用>

  1. 不知何故使用 IE 中的 ExternalInterface 和其他浏览器返回给我当前网址.

    OR

  2. 在标签上添加一个 id="PA" 属性并让 AS3 读取该标签并将其作为字符串拉入,没有使用 JavaScript

我的限制是我只能将标签添加到 HTML 中,而不能添加任何 JavaScript 函数.这必须在 AS3 中严格完成.

不管怎样,我都需要知道我在哪个 URL 上.非常感谢任何帮助.

解决方案

为了使其在 IE 中工作,您需要做一些事情.首先是 ActionScript:

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

其次,您需要 <object> 标签中的有效 classid 和 id 属性:

如果不放置这些属性,ExternalInterface.call 在 IE6/7/8 中总是返回 null,但在 Firefox 中按预期工作.

第三,您需要将参数allowScriptAccess设置为'always',以启用ExternalInterface.

..<嵌入 allowscriptaccess='always' ...>

.....

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.

解决方案

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' ...>

.....

这篇关于使用 ExternalInterface 和 IE 从 JavaScript 获取 Flash 中的当前 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆