Flex-调用JavaScript函数并打开一个显示数据的弹出窗口

Flex-调用JavaScript函数并打开一个显示数据的弹出窗口,javascript,html,flash,apache-flex,externalinterface,Javascript,Html,Flash,Apache Flex,Externalinterface,我一直在努力解决这个问题 我有一个Flex(Flash)应用程序,我被称为JavaScript函数并传递数据: if (ExternalInterface.available) ExternalInterface.call("jsFunctionToCalled", passingSomeData); 在我的index.template.html文件中,我创建了JS函数: <script type="text/javascript"> function jsFunctionToCa

我一直在努力解决这个问题

我有一个Flex(Flash)应用程序,我被称为JavaScript函数并传递数据:

if (ExternalInterface.available)
ExternalInterface.call("jsFunctionToCalled", passingSomeData);
在我的index.template.html文件中,我创建了JS函数:

<script type="text/javascript">
function jsFunctionToCalled(value) {
window.alert(value);
}
</script>  

函数jsFunctionToCalled(值){
窗口报警(值);
}
当我在Flex中单击按钮组件时,会弹出JS警报窗口。这很好;但是,我想打开一个浏览器窗口,在那里我可以访问“文件/打印”选项。我需要打开这个新的浏览器窗口并解析value对象中的数据。值对象是一个HTML格式的数据字符串。所以我需要在新的弹出窗口中显示这些数据。我在想也许我需要做一些类似的事情,有人在某个地方发布了,但什么也没有弹出。我也试过开窗器,但什么也没出现。如果我提供一个URL,它会很好地打开URL,但我不想打开URL,我想打开一个可以打印的新窗口,并用HTML数据填充该窗口

<script>
function openWin()
{
myWindow=window.open('','','width=200,height=100');
myWindow.document.write("This is 'myWindow'!");
myWindow.focus();
myWindow.opener.document.write("<p>This is the source window!</p>");
}
</script>

函数openWin()
{
myWindow=window.open('','',宽度=200,高度=100');
myWindow.document.write(“这是‘myWindow’!”);
myWindow.focus();
myWindow.opener.document.write(“这是源窗口!

”; }
任何帮助都将不胜感激。我正在试图找到一种打印的方法,不需要先保存文件(蹩脚的FLASH),而且我没有一个web服务器来保存我的文件,以避免先保存文件


谢谢

我发现了这个问题,我想我会把它分享给其他遇到这个问题的人:

在我的Flex代码中:

if (ExternalInterface.available)
            {
                try
                {
                    ExternalInterface.call("onPrintRequest", dataToPass);
                }
                catch (error:SecurityError)
                {
                    Alert.show("Printing Security Error");
                }
                catch (error:Error)
                {
                    Alert.show("Printing Error");
                }
            }
            else
            {
                Alert.show("Printing currently unavailable");
            }
在我的index.template.html中,我添加了以下JS方法:

 <script type="text/javascript">
            function onPrintRequest(value) {
                var w = window.open("about:blank");
                w.document.write(value);
                w.document.close();
                w.focus();
                w.print();
            }
        </script>

函数onPrintRequest(值){
var w=窗口打开(“关于:空白”);
w、 文件。写入(值);
w、 document.close();
w、 焦点();
w、 打印();
}

工作就像一个魅力

我发现了这一点,并想与其他遇到此问题的人分享:

在我的Flex代码中:

if (ExternalInterface.available)
            {
                try
                {
                    ExternalInterface.call("onPrintRequest", dataToPass);
                }
                catch (error:SecurityError)
                {
                    Alert.show("Printing Security Error");
                }
                catch (error:Error)
                {
                    Alert.show("Printing Error");
                }
            }
            else
            {
                Alert.show("Printing currently unavailable");
            }
在我的index.template.html中,我添加了以下JS方法:

 <script type="text/javascript">
            function onPrintRequest(value) {
                var w = window.open("about:blank");
                w.document.write(value);
                w.document.close();
                w.focus();
                w.print();
            }
        </script>

函数onPrintRequest(值){
var w=窗口打开(“关于:空白”);
w、 文件。写入(值);
w、 document.close();
w、 焦点();
w、 打印();
}

工作就像一个魅力

上述更改非常有效

添加一项-如果要在打印后自动关闭新窗口,请在脚本中添加w.close()

 <script type="text/javascript">
 function onPrintRequest(value) {
            var w = window.open("about:blank");
            w.document.write(value);
            w.document.close();
            w.focus();
            w.print();
            w.close();
        }
</script>

函数onPrintRequest(值){
var w=窗口打开(“关于:空白”);
w、 文件。写入(值);
w、 document.close();
w、 焦点();
w、 打印();
w、 close();
}

上述更改非常有效

添加一项-如果要在打印后自动关闭新窗口,请在脚本中添加w.close()

 <script type="text/javascript">
 function onPrintRequest(value) {
            var w = window.open("about:blank");
            w.document.write(value);
            w.document.close();
            w.focus();
            w.print();
            w.close();
        }
</script>

函数onPrintRequest(值){
var w=窗口打开(“关于:空白”);
w、 文件。写入(值);
w、 document.close();
w、 焦点();
w、 打印();
w、 close();
}

您是否检查了弹出窗口阻止程序是否阻止了它?它在没有通过flash函数调用的情况下工作了吗?@fmodos不幸的是我这样做了。我关闭了弹出窗口拦截器,并在IE和Firefox中进行了尝试。尝试在没有flash集成的情况下打开此窗口,我的意思是创建一个简单的html按钮并调用openWin@fmodos用这个URL打开一个窗口是有效的,集成在Flash中。但是我需要打开一个新的空白窗口(像一个新面板),用传入的一些数据填充这个新窗口。当我提供一个URL时,我只能在(Flex)Flash中打开一个窗口。你检查过弹出窗口阻止程序阻止了它吗?它在没有通过flash函数调用的情况下工作了吗?@fmodos不幸的是我这样做了。我关闭了弹出窗口拦截器,并在IE和Firefox中进行了尝试。尝试在没有flash集成的情况下打开此窗口,我的意思是创建一个简单的html按钮并调用openWin@fmodos用这个URL打开一个窗口是有效的,集成在Flash中。但是我需要打开一个新的空白窗口(像一个新面板),用传入的一些数据填充这个新窗口。当我提供URL时,我只能在(Flex)Flash中打开一个窗口。