IE 11 DispatchEvent - javascript

We have a datepicker (in JavaScript) that has a section for checking IE 8 and older and other modern browsers.
if(-1 != navigator.userAgent.indexOf("MSIE")){
obj_caller.target.fireEvent("onchange");
}
else {
var evt = document.createEvent("HTMLEvents");
evt.initEvent("change", false, true);
obj_caller.target.dispatchEvent(evt);
}
It's working fine in Chrome, Firefox, IE8 and below but is failing in IE 11. What I need is a way to get the else part working in IE 11. I just cannot figure out what is failing and how to fix it.
Thanks.

Your problem is that fireEvent shouldn't be used in newer IE versions. Support for dispatchEvent was added in IE9. http://help.dottoro.com/ljrinokx.php
if(document.createEventObject) {
obj_caller.target.fireEvent("onchange");
} else {
var evt = document.createEvent("HTMLEvents");
evt.initEvent("change", false, true);
obj_caller.target.dispatchEvent(evt);
}

Related

JavaScript code detects IE 10 as supported version instead of as out of date

The code below generates alert "Your browser is supported" even if the version is IE 10. It works perfectly with browsers such as IE 9, 8 and 7. I need to ensure only version IE 11 is allowed. Is there really anything wrong with the code?
<script type="text/javascript">
jQuery(document).ready(function($){
// true on IE11
// false on Edge and other IEs/browsers. filters.hide();
// Allow only IE 11 and other browsers like Chrome, Safar, firefox so on,
// but never allow lower versions of IE starting IE 10.
var div = document.createElement("div");
div.innerHTML = "<!--[if lt IE 11]><i></i><![endif]-->";
var isIeLessThan11 = (div.getElementsByTagName("i").length == 1);
if (isIeLessThan11) {
alert("Your web browser is out of date. Please complete this form using an approved browser, such as Edge, Chrome, Safari, or Firefox.");
} else {
alert("Your browser is supported");
}
});
</script>
According to wikipedia, conditional comments are not supported in IE10 and above. https://en.m.wikipedia.org/wiki/Conditional_comment

Swfobject.js library's getFlashPlayerVersion() function works incorrectly

When I use swfobject.getFlashPlayerVersion() on IE11 with flash version older than current 15.0.0, I always get "0.0.0" as the result. (with version 15 it works correctly)
I have tested it with both flash player plugin on FF and active x on IE. With Firefox, everything works correctly. Swfobject FAQ states in question 3 that some versions may give incorrect results, but it does not mention returning "0.0.0" and also I have tested flash player versions 9, 10, 10.2, 10.3, 11.3 and 13 and the result in IE was always the same.
I really need to get the correct version of flash player installed in IE. Is there any solution to this problem? Are there any other options how to reliably get the correct flash player version?
EDIT: There was a question what swfobject does to look up the version. Well this is the part of the code that does it:
if (typeof nav.plugins != UNDEF && typeof nav.plugins[SHOCKWAVE_FLASH] == OBJECT) {
d = nav.plugins[SHOCKWAVE_FLASH].description;
if (d && !(typeof nav.mimeTypes != UNDEF && nav.mimeTypes[FLASH_MIME_TYPE] && !nav.mimeTypes[FLASH_MIME_TYPE].enabledPlugin)) { // navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin indicates whether plug-ins are enabled or disabled in Safari 3+
plugin = true;
ie = false; // cascaded feature detection for Internet Explorer
d = d.replace(/^.*\s+(\S+\s+\S+$)/, "$1");
playerVersion[0] = parseInt(d.replace(/^(.*)\..*$/, "$1"), 10);
playerVersion[1] = parseInt(d.replace(/^.*\.(.*)\s.*$/, "$1"), 10);
playerVersion[2] = /[a-zA-Z]/.test(d) ? parseInt(d.replace(/^.*[a-zA-Z]+(.*)$/, "$1"), 10) : 0;
}
}
else if (typeof win.ActiveXObject != UNDEF) {
try {
var a = new ActiveXObject(SHOCKWAVE_FLASH_AX);
if (a) { // a will return null when ActiveX is disabled
d = a.GetVariable("$version");
if (d) {
ie = true; // cascaded feature detection for Internet Explorer
d = d.split(" ")[1].split(",");
playerVersion = [parseInt(d[0], 10), parseInt(d[1], 10), parseInt(d[2], 10)];
}
}
}
catch(e) {}
}
I found out that in IE10 it goes to the else if part (flash version does not matter) while in IE11 with flash 15 it goes to the first if . However, with IE11 and older flash it skips both conditions:
window.ActiveXObject is undefined in IE11 (as it should be, or at least that's what I have found)
but it also skips the first if and when I look at navigator.plugins there aren't any despite having the flash 11.0 installed
Where is the problem? Why the older flash is not listed in my IE11 plugins?

Detect if any kind of IE (MSIE) [duplicate]

This question already has answers here:
Internet Explorer 11 detection
(12 answers)
Closed 8 years ago.
I dont want to allow users to access my site with Microsoft Internetexplorer (ANY VERSION).
What I´ve found so far was to detect if it´s lower or equal version 10.
A very annoing thing: Internetexplorer >v10 doesn´t admit to be a InternetExplorer.
What i´ve found and tried so far:
if(navigator.appVersion.indexOf("MSIE")!=-1){
alert("You use IE. That´s no good.");
}
or
if ( $.browser.msie ) {
alert( $.browser.version );
}
and
http://msdn.microsoft.com/en-us/library/ie/ms537509%28v=vs.85%29.aspx
I would use any solution if it is in javascript, jquery or php if there is one.
This works for me to detect any Version of the IE 5-11 (Internet Explorer) (Aug/05/2014):
if (navigator.appName == 'Microsoft Internet Explorer' || !!(navigator.userAgent.match(/Trident/) || navigator.userAgent.match(/rv:11/)) || (typeof $.browser !== "undefined" && $.browser.msie == 1))
{
alert("Please dont use IE.");
}
This is because each release of Internet Explorer updates the user-agent string.
MSIE tokens have been removed in Internet Explorer 11 and $.browser uses navigator.userAgent to determine the platform and it is removed in jQuery 1.9.
You can use following code to determine the browser with pure java-script.
var isIE = !!navigator.userAgent.match(/Trident/g) || !!navigator.userAgent.match(/MSIE/g);
if(isIE){
alert("IE");
}
else{
alert("Not IE");
}
Thanks!
if you are not interessted wich version of ie the user currently use you can try get it work with detecting if the browser supports the Conditional Compilation Statements
http://msdn.microsoft.com/en-us/library/7kx09ct1%28v=vs.80%29.aspx
if(/*#cc_on!#*/false)
{
// You use IE. That´s no good.
alert("oh my god");
}
You can use conditional compilation
, e.g.
<script>
var isIE = false;
/*#cc_on isIE = true; #*/
</script>
But note that IE11 doesn't observe this in Standards Mode. User Agent sniffing is generally a bad idea, but as IE becomes more standards-compliant, it also becomes harder to detect (hopefully also meaning less need to)
For IE> 10 which is currently IE 11, user-agent carries something in Browser's HTTP request headers
Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko
You can put a check on "rv:11.0" for version 11. Let me know if you need code for this.
I've found (maybe in SO) in the past this script and it worked for me (IE 10 too)
<![if IE]>
<script type='text/javascript'>
if(/*#cc_on!#*/false)
var bIsIE = 1;
</script>
<![endif]>
and then
if (typeof (bIsIE) != 'undefined')
{
//IE :(
}
else
{
//NOT IE :)
}

Alternative .execCommand('insertText') for Opera

Seems like in Opera, can't use command InsertText
document.queryCommandEnabled('insertText'); // false
but
document.queryCommandEnabled('insertHTML'); // true
How can i get this work in Opera ?
document.execCommand('insertText', false, 'test');
Use window.opera for checking Opera, but which commands are supported, as well as their behavior varies across browsers. Firefox commands you can see here. For IE here.

document.onmouseover and onmouseout event parameter is undefined in IE 8 and IE7

Parameter e is the correct event in Chrome, FF and IE 9 but 'undefined' in IE 8 and IE 7. Reproducable in IE 9 using F12 devtools Browser Mode: IE 8 and Document Mode: IE 8 also.
NOTE: The function is called properly my 'only' problem that e is undefined...
<script>
document.onmouseover = function(e) {
// parameter e is the correct event in Chrome, FF and IE 9
// but 'undefined' in IE 8 and IE 7. Reproducable in IE 9 using F12 devtools
// Browser Mode: IE 8 and Document Mode: IE 8 also.
// NOTE: The function is called properly my 'only' problem that e is undefined
... work with parameter e here
}
</script>
Any ideas?
Thy in advance
IE does events differently, hence why it does not work.
document.onmouseover = function(e) {
e = e || window.event;
}

Categories

Resources