简体   繁体   English

简化强制IE11在谷歌浏览器中打开链接的JS

[英]Simplify the JS that forces IE11 to open a link in google chrome

I did have a short cut to a post here that explained how to combine the code below to make it easier for me to use it on muliple links.我确实有一条捷径到这里的一篇文章,解释了如何组合下面的代码,以便我更容易在多个链接上使用它。

Our company (for the time being is forcing us to use IE11) and I need to be able to add a link to a webpage that opens it in google chrome.我们公司(暂时强迫我们使用 IE11),我需要能够添加一个链接到在谷歌浏览器中打开它的网页。 The code I have is:我的代码是:

<script type="text/javascript">
    function openURL1()
        {
        var shell = new ActiveXObject("WScript.Shell");
        shell.run("Chrome https://hotmail.com/");
        }
        function openURL2()
        {
        var shell = new ActiveXObject("WScript.Shell");
        shell.run("Chrome https://google.com/");
        }
</script>

<TD COLSPAN="2" STYLE= WIDTH="100"> <input type="button" style ="background-color:grey" onclick="openURL1()" value="Support Net"></TD>
<TD COLSPAN="2" STYLE= WIDTH="100"> <input type="button" style ="background-color:grey" onclick="openURL2()" value="Communities"></TD>

Just want to display link to click on thats all.只想显示链接以单击仅此而已。 1 I don't need to do anything but i have several links that I need to add. 1 我不需要做任何事情,但我有几个链接需要添加。 HTML code I can work my way round but I am still a newbie when it comes to JS and struggle still. HTML 代码我可以按自己的方式工作,但在 JS 方面我仍然是新手并且仍在挣扎。 cheers干杯

If i read your request correct, you're looking for something like:如果我正确阅读了您的请求,则您正在寻找类似的内容:

function openURL(url) {
  let shell = new ActiveXObject("WScript.Shell");
  shell.run("Chrome " + url);
}

a single function with the url as a parameter, so you can reuse it?单个 function 和 url 作为参数,这样可以重复使用吗?

Html body portion following your current example: Html 主体部分遵循您当前的示例:

<TD COLSPAN="2" STYLE="WIDTH: 100;"> <input type="button" style ="background-color:grey;" onclick="openURL('https://hotmail.com/')" value="Support Net"></TD>
<TD COLSPAN="2" STYLE="WIDTH: 100;"> <input type="button" style ="background-color:grey;" onclick="openURL('https://google.com/')" value="Communities"></TD>
<TD COLSPAN="2" STYLE="WIDTH: 100;"> <input type="button" style ="background-color:grey;" onclick="openURL('https://stackoverflow.com/')" value="Helpful People"></TD>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM