I don't want users to see the "install missing plugin" on their firefox when a custom plugin isn't found. How do I disable this?
<object height="0" width="0" id="mycustomPlugin" type="application/x-vnd-puppyt">开发者_JS百科</object>
One way to do this -- there might be others -- is to check to see whether it's listed in the navigator.plugins array before creating the object tag. Something like this (some sample code cut-and-pasted from a recent project):
function createVncServer(id) {
console.log(navigator.userAgent);
var vncDiv = document.getElementById("vncDiv");
if (navigator.userAgent.indexOf("MSIE") > -1) {
vncDiv.innerHTML = "<object id='" + id + "' classid='CLSID:42832F4C-3480-4450-A6B5-156B2EFC408F' codebase='http://localhost:51150/Resources/WinVncCtlInstaller.CAB' />";
}
else {
// On Mozilla browsers, check to make sure the plugin is installed before we try to instantiate it, to avoid the weird "plugins required" message.
var pluginInstalled = false;
for (var i = 0; i < navigator.plugins.length; i++) {
console.log(navigator.plugins[i].name);
if (navigator.plugins[i].name == 'Alanta Remote Desktop Server') {
pluginInstalled = true;
}
}
if (pluginInstalled) {
vncDiv.innerHTML = "<object id='" + id + "' type='application/x-alanta-vnc' />";
}
else {
promptForDownload();
return null;
}
}
var vncServer = document.getElementById(id);
try {
if (vncServer.Port > 0) {
clearDownloadPrompt();
return vncServer;
}
else {
promptForDownload();
}
}
catch (ex) {
promptForDownload();
}
}
精彩评论