简体   繁体   中英

Javascript code to force html page to open in Chrome browser?

We are using Google Apps at our company and everyone has Chrome installed on their computers. The problem is that we still have to use IE for certain things. I have a few html files on our intranet site that link to Google Docs, but it's opening in an IE browser. I need it to open a Chrome browser so the user doesn't have to sign in each time they open the file. I only have control of the html files settings so is there any way to use Javascript to force a window to open in Chrome?

Thanks!

I believe that if you're using IE you can use ActiveX to open up specific programs.

For instance try looking at 'new ActiveXObject'

You must explicitly allow this however as IE confirms if you want to allow it to be executed.

function loadProg(path){
    var active = new ActiveXObject("WScript.Shell");
    activeX = active.Run(path);
}

If you know the direct file path use this like

loadProg(path);

More specifically like

window.onload = function(){
    loadProg("\"C:\\Program Files (x86)\\Guitar Pro 5\\GP5.exe\"");
};

I don't know the path to Chrome so i used something else instead.

Check if current browser is chrome:

var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;

if not, alert user to show a message.

Are you asking if you can open a Chrome window from Javascript in an IE window? If so, then no, this is not possible. Javascript code in browsers run within a very strict sandbox that would not permit you to make any system calls. Opening a Chrome window from IE would effectively require you to execute chrome.exe on the client's machine. I'm sure you can see how this ability, if granted, could be misused to execute malicious exe's on the client' system.

I am quite sure that the best you can do using JavaScript is show a message to the user and tell them to open the file in Chrome instead. JavaScript does not have the right to execute an external application such as Chrome. See http://www.w3schools.com/js/js_browser.asp for information about detecting the browser using JavaScript.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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