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

5cnsuln7  于 2022-11-01  发布在  Apache
关注(0)|答案(2)|浏览(133)

我一直想弄明白...
我有一个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>

当我单击Flex中的Button组件时,JS警报窗口会弹出。然而,我想打开一个浏览器窗口,在那里我可以访问“文件/打印”选项。我需要打开这个新的浏览器窗口,并解析来自值对象的数据。值对象是HTML格式的数据字符串。所以我需要在新的弹出窗口中显示这些数据。我在想,也许我需要做一些类似这样的事情,有人张贴在某处,但没有弹出任何内容。我也尝试了window.opener,但没有弹出任何内容。如果我提供了一个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>

任何帮助都将不胜感激。我正在想办法能够打印,而不需要先保存文件(蹩脚的闪存),而且我没有网络服务器来保存我的文件,以避免先保存文件。
谢谢

s4n0splo

s4n0splo1#

我想通了这一点,并认为我会分享给其他任何人经历这个问题:
在我的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>

工作起来就像一个魅力!

yxyvkwin

yxyvkwin2#

上述更改工作完美....
一个补充--如果你想在打印后自动关闭新窗口,在脚本中添加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>

相关问题