在Firefox中启动HTML文件

时间:2018-10-05 04:27:54

标签: javascript

我正在尝试在firefox中自动启动HTML文件

我们公司已将IE设置为默认值,并且该文件旨在在firefox中启动以正常工作

这是我必须检查的代码,但是由于某些原因,它并不能正常工作

文件路径正确,这是我想到的第一件事

有人可以协助吗?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        <link rel="stylesheet" href="opener_files/opener.css" media="screen" type="text/css">
        <script type="text/javascript">
            function codeAddress(){
                if (browserName = "Internet Explorer");
                var shell = new ActiveXObject("WScript.Shell");
                shell.run('"Firefox" "file:///Mel19a001ppn/transfer/L&D_LT&S/SimonW/Sean/DEBT T1 Re-design/SD_Debt_Systems_Introduction/intro.html"');
                }

                    window.onload = codeAddress;
                    window.setTimeout(CloseMe);

            function CloseMe() 
            {
            window.open('','_parent','');
            window.close();
            }
        </script>
    </head>
</html>

编辑:

我还玩了一些,让它运行并启动了Firefox

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        <link rel="stylesheet" href="opener_files/opener.css" media="screen" type="text/css">
        <script type="text/javascript">
            function codeAddress(){ 
                if (navigator.userAgent.indexOf("MSIE") != -1 ) {
                    var shellApp = new ActiveXObject("Shell.Application");
                    var commandtoRun ="C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe";
                    shellApp.ShellExecute(commandtoRun,"","", "open", "3");
                }

            }   
            window.onload = codeAddress;
            window.setTimeout(CloseMe);

            function CloseMe() 
            {   
                window.open('','_parent','');
                window.close();
            }
        </script>
    </head>
</html>

这可以正确打开Firefox,但是现在我不知道如何加载我拥有的文件路径

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

您可以从Windows注册表中获取FireFox的安装路径,如下所示:

var shell = new ActiveXObject("WScript.Shell"),
    cVer = shell.RegRead('HKLM\\SOFTWARE\\Mozilla\\Mozilla Firefox\\currentVersion'),
    FF = '"' + shell.RegRead('HKLM\\SOFTWARE\\Mozilla\\Mozilla Firefox\\' + cVer +'\\Main\\PathToExe') + '"';

然后尝试运行FireFox:

shell.Run(FF + ' "\\\\Mel19a001ppn\\transfer\\L&D_LT&S\\SimonW\\Sean\\DEBT T1 Re-design\\SD_Debt_Systems_Introduction\\intro.html"');