ExternalInterface.call(“window.location.host.toString”)

发布于 2024-08-01 20:06:11 字数 4258 浏览 2 评论 0原文

我编写了一个 Flex 应用程序,使用此代码从浏览器获取主机字符串。

ExternalInterface.call("window.location.host.toString")

这行代码可以完美地在 Firefox 和 Opera 中获取主机字符串。 但是,当使用 IE 时,返回的字符串始终为“null”。 我需要从浏览器获取此类信息。 我知道有一种解决方法,可以定义一个获取此类字符串的 JavaScript 函数并从应用程序调用该函数。 但是,我的应用程序需要从本机源获取此类信息。

我想知道是否有人遇到同样的问题并设法解决它,或者是否有人知道为什么我在 IE 中总是得到 null,但在使用 Firefox 和 Opera 时却不然

编辑 1:

这是用于嵌入生成的 SWF 文件的 HTML 代码。 错误很有用,

<object id="myTest1" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" height="330px" width="600px">
<param name="movie" value="http://www.website.com/test.swf" />
<param name="allowScriptAccess" value="always" />
<param name="wmode" value="transparent" />
<embed id="myTest1" pluginspage="http://www.macromedia.com/go/getflashplayer" src="http://www.website.com/test.swf" allowScriptAccess="always" wmode="transparent" height="330px" width="600px" flashvars=""></embed>
</object>

也许这对于发现id、classid 和 allowedScriptAccess 设置如图所示的

有什么想法吗?

编辑 2:

为 Lior Cohen Flex 文件是第一个链接中使用的示例。 子目录history包含history.js、history.css和historyFrame.html。 包含生成的 SWF 文件的 HTML 页面如下所示

<html>
<head>
<!--  BEGIN Browser History required section -->
<link rel="stylesheet" type="text/css" href="history/history.css"/>
<script src="history/history.js" language="javascript"></script>
<!--  END Browser History required section -->
</head>
<body>
<object id="file1" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" height="330px" width="600px">
    <param name="movie" value="file.swf" />
    <param name="allowScriptAccess" value="always" />
    <param name="wmode" value="transparent" />
    <embed id="file2" pluginspage="http://www.macromedia.com/go/getflashplayer" src="file.swf" allowScriptAccess="always" wmode="transparent" height="330px" width="600px" flashvars=""></embed>
</object>
<body>
</html>

但是,这仍然无法按预期工作。

编辑3:

我发现了这个问题,但是我无法修复它。 该问题与 IE 的 javascript 引擎有关,而不是与外部接口有关,也与对象和嵌入 HTML 标签无关。

在我的例子中,我正在做的是将对象写入并将标签嵌入到使用 javascript 创建的 div 中,并使用 DOM 方法将该 div 附加到正文的末尾。 然而,这种方法使得InternalInterface在IE中总是返回null(但在Firefox和Opera中则不然)。

var swfDiv = document.createElement('div');
swfDiv.innerHTML = '<object id="test1" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="600" height="330"><param name="movie" value="http://www.website.com/test.swf" /><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="false" /><param name="quality" value="high" /><embed id="test2" name="test2" src="http://www.website.com/test.swf" allowScriptAccess="always" allowFullScreen="false" quality="high" width="600" height="330" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';
document.body.appendChild(swfDiv);

我尝试使用 document.write 附加 HTML 内容,这使得它在 IE 中完美工作,但是 document.write 写入了整个页面(删除旧内容),这是我不想要的。

document.write('<object id="test1" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="600" height="330"><param name="movie" value="http://www.website.com/test.swf" /><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="false" /><param name="quality" value="high" /><embed id="test2" name="test2" src="http://www.website.com/test.swf" allowScriptAccess="always" allowFullScreen="false" quality="high" width="600" height="330" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>');

知道如何解决这个问题吗?

谢谢

I wrote a flex application that get the host string from the browser using this code

ExternalInterface.call("window.location.host.toString")

This line of code work prefectally to get the host string in both Firefox and Opera. However, when using IE, the returned string is always 'null'. I need to get such information from the browser. I know that there is a work around by defining a javascript function that get such string and calling that function from the application. However, my application require getting such information from a native source.

I was wondering if anyone had the same problem and managed to solve it, or if someone has any idea why I always get null in IE, but not when using Firefox and Opera

Edit 1:

Here is the HTML code for embedding the generated SWF file. Maybe this is useful to spot a mistake

<object id="myTest1" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" height="330px" width="600px">
<param name="movie" value="http://www.website.com/test.swf" />
<param name="allowScriptAccess" value="always" />
<param name="wmode" value="transparent" />
<embed id="myTest1" pluginspage="http://www.macromedia.com/go/getflashplayer" src="http://www.website.com/test.swf" allowScriptAccess="always" wmode="transparent" height="330px" width="600px" flashvars=""></embed>
</object>

the id, classid, and the allowScriptAccess are set as shown

Any idea?

Edit 2:

for Lior Cohen
The Flex file is the example used in your first link. The sub-directory history contains history.js, history.css, and historyFrame.html. The HTML page that include the generated SWF file is like this

<html>
<head>
<!--  BEGIN Browser History required section -->
<link rel="stylesheet" type="text/css" href="history/history.css"/>
<script src="history/history.js" language="javascript"></script>
<!--  END Browser History required section -->
</head>
<body>
<object id="file1" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" height="330px" width="600px">
    <param name="movie" value="file.swf" />
    <param name="allowScriptAccess" value="always" />
    <param name="wmode" value="transparent" />
    <embed id="file2" pluginspage="http://www.macromedia.com/go/getflashplayer" src="file.swf" allowScriptAccess="always" wmode="transparent" height="330px" width="600px" flashvars=""></embed>
</object>
<body>
</html>

However, this is still not working as expected.

Edit 3:

I have spotted the problem, however, I cannot fix it. The problem has to do with the javascript engine of IE and not the ExternalInterface nor the object and embed HTML tags.

What I am doing in my case is write the object and embed tags into a div created using javascript and this div is appended to the end of the body using the DOM methods. However, such approach make the InternalInterface always return null in IE (but not in Firefox nor in Opera).

var swfDiv = document.createElement('div');
swfDiv.innerHTML = '<object id="test1" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="600" height="330"><param name="movie" value="http://www.website.com/test.swf" /><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="false" /><param name="quality" value="high" /><embed id="test2" name="test2" src="http://www.website.com/test.swf" allowScriptAccess="always" allowFullScreen="false" quality="high" width="600" height="330" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';
document.body.appendChild(swfDiv);

I tried to use document.write to append the HTML content, which made it work perfectly in IE, however, document.write wrote over the entire page (removing old content), which is something I don't want.

document.write('<object id="test1" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="600" height="330"><param name="movie" value="http://www.website.com/test.swf" /><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="false" /><param name="quality" value="high" /><embed id="test2" name="test2" src="http://www.website.com/test.swf" allowScriptAccess="always" allowFullScreen="false" quality="high" width="600" height="330" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>');

Any idea how to fix this?

Thanks

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

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

发布评论

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

评论(5

把人绕傻吧 2024-08-08 20:06:11

看看下面的链接。 它应该为您提供您正在寻找的内容,而无需使用ExternalInterface.call()。

http://livedocs.adobe.com/flex/ 3/html/help.html?content=deep_linking_7.html

如上页所述,为了让 BrowserManager 类提供其完整功能,包装器必须包含几个支持文件(history.js 等)。

有关如何获取和使用这些支持文件的更多信息,请参阅“部署使用深度链接的应用程序”部分下的以下链接。

http://livedocs.adobe.com/flex/ 3/html/help.html?content=deep_linking_2.html

Take a look at the following link. It should provide you with what you're looking for, without using ExternalInterface.call().

http://livedocs.adobe.com/flex/3/html/help.html?content=deep_linking_7.html

As mentioned in the page above, for the BrowserManager class to offer its full functionality, the wrapper must include several supporting files (history.js, amongst others).

More information about how to obtain and use these supporting files can be found in the following link under the "Deploying applications that use deep linking" section.

http://livedocs.adobe.com/flex/3/html/help.html?content=deep_linking_2.html

本宫微胖 2024-08-08 20:06:11

使用 SWFObject(您可以在 http://code.google.com/p/swfobject/ 找到它)将Flash放置在页面上也解决了Internet Explorer中的这个问题。

Using SWFObject (you'll find it at http://code.google.com/p/swfobject/) to place the Flash on the page also solves this problem in Internet Explorer.

心碎无痕… 2024-08-08 20:06:11

快速搜索表明您必须在对象上设置一些额外的属性才能使其在 IE 中工作。 设置 id classId 和 scriptAccess(当然最后一个为“true”)以使其正常工作。 (通过 google 了解更多信息)

(未经测试。)

http://www.google .com/search?q=externalinterface+internet+explorer

A quick search reveals you will have to set some extra attributes on the object to make it work in IE. Set id classId and scriptAccess (the last one to 'true' of course) to get this to work. (google for more info)

(Not tested.)

http://www.google.com/search?q=externalinterface+internet+explorer

紫罗兰の梦幻 2024-08-08 20:06:11

@AAA

注2:最后一行是使其正常工作所必需的,并且必须类似于
以及将对象添加到文档后的最后。 我不知道
为什么,可能与奇怪的浏览器行为有关。

非常感谢 ! 我认为这是 IE 中的一个错误。 我想知道你是怎么发现的。

@AAA

Note 2: the last line is required to make it work properly, and it has to be like
that and at the end after adding the object to the document. I do not know
why, probably it has to do with the weird browser behavior.

Thank you very much ! I suppose it is a bug in IE. I wonder how you found out.

む无字情书 2024-08-08 20:06:11

“编辑3”中提到的问题的解决方案基本上是使用DOM对象创建对象标签及其参数标签,而不是仅仅将它们指定为innerHTML属性的字符串。 这将使ExternalInterface 的返回值在Internet Explorer 中起作用。 下面是一个示例:

var swfDiv = document.createElement('div');

var obj = document.createElement('object');
obj.setAttribute('id','test1');
obj.setAttribute('codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0');
obj.setAttribute('width','600px');
obj.setAttribute('height','330px');

var param = document.createElement('param');
param.setAttribute('name','movie');
param.setAttribute('value','http://www.website.com/test.swf');
obj.appendChild(param);

param = document.createElement('param');
param.setAttribute('name','allowScriptAccess');
param.setAttribute('value','always');
obj.appendChild(param);

param = document.createElement('param');
param.setAttribute('name','wmode');
param.setAttribute('value','transparent');
obj.appendChild(param);

swfDiv.appendChild(obj);
document.body.appendChild(swfDiv);

document.getElementById('test1').setAttribute('classid','clsid:d27cdb6e-ae6d-11cf-96b8-444553540000');

注 1:这将使其适用于 Internet Explorer,任何其他浏览器都应使用问题的“编辑 3”中提到的任何方法。 您可以检测浏览器并相应地使用正确的代码。

注2:最后一行是使其正常工作所必需的,并且必须是这样的,并且在将对象添加到文档之后的末尾。 我不知道为什么,可能与奇怪的浏览器行为有关。

The solution to the problem that is mentioned in "Edit 3" is basically to create the object tag and its parameter tags using DOM objects, instead of just specifying them as string for the innerHTML attribute. This will make the returned value of the ExternalInterface work in Internet Explorer. Here is an example:

var swfDiv = document.createElement('div');

var obj = document.createElement('object');
obj.setAttribute('id','test1');
obj.setAttribute('codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0');
obj.setAttribute('width','600px');
obj.setAttribute('height','330px');

var param = document.createElement('param');
param.setAttribute('name','movie');
param.setAttribute('value','http://www.website.com/test.swf');
obj.appendChild(param);

param = document.createElement('param');
param.setAttribute('name','allowScriptAccess');
param.setAttribute('value','always');
obj.appendChild(param);

param = document.createElement('param');
param.setAttribute('name','wmode');
param.setAttribute('value','transparent');
obj.appendChild(param);

swfDiv.appendChild(obj);
document.body.appendChild(swfDiv);

document.getElementById('test1').setAttribute('classid','clsid:d27cdb6e-ae6d-11cf-96b8-444553540000');

Note 1: This will make it work with Internet Explorer, any other browser should use any of the method mentioned above in "Edit 3" of the question. You can detect the browser and use the proper code accordingly.

Note 2: the last line is required to make it work properly, and it has to be like that and at the end after adding the object to the document. I do not know why, probably it has to do with the weird browser behavior.

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