I created a function in Javascript
function addName(okDelete = true){
amountExtraStudents++;
if(amountExtraStudents > 2){
preisAktuell = 60;
}
if(!okDelete){
jQuery('#teilnehmerExtra').append('<div class="teilnehmer-1"></div>');
}else{
jQuery('#teilnehmerExtra').append('<div class="teilnehmer-2"></div>');
}
eintragNummer++;
updateButtons();
}
But in Edge I get this error:
In Safari I dont get any Error - but the Function - and all the other functions in the rest of the Script Block are not working.
It works out fine in Chrome, Firefox and Opera, but not in Safari, IE and Edge...
Is there something incompatible with the Browser?
The error is occuring when you use the 'default parameters' feature introduced in ES6. Edge does not support it.
An ES5 version would be:
function addName(okDelete){
if (typeof okDelete === "undefined") {
okDelete = true;
}
You might also consider using a tool such as Babel to transpile your ES6 into ES5.
Related
How do I use ... within IE with the code below? I'm new to using ... and it's hard for me to convert it so that it works with IE11.
I'm using angularJS here, but the code below isn't working on IE and it's throwing a syntax error at ...new. Sadly, I can't use babel in this instance.
scope.model.locations = res.sort(function(a, b) {
(a.locationName > b.locationName) ? 1: -1
});
scope.model.jobCategories = [...new Set(scope.model.jobCategories)];
I am using this JS code to add a class on a activate bootstrap 4 navigation link, and on most browsers it is working, but on IE11 not. Any idea why?
"use strict";
var nav = document.querySelector('.navbar');
var links = nav.querySelectorAll('.highlight');
links.forEach(function(link){
if (link.href == window.location.href.split("#")[0]) {
link.classList.add('active');
}
});
links.forEach(function(link){
link.addEventListener('click', function(e) {
links.forEach(function(link){
link.classList.remove('active');
});
this.classList.add('active');
});
});
var kontaktLink = document.querySelector('.kontaktLink');
var navBarToggle = document.getElementById('navbarSupportedContent');
var togglerButton = document.querySelector('.navbar-toggler');
kontaktLink.addEventListener('click', function() {
if (navBarToggle.classList.contains('show')) {
navBarToggle.classList.remove('show');
navBarToggle.classList.add('collapse');
togglerButton.classList.add('collapsed');
togglerButton.setAttribute('aria-expanded','false');
}
});
Because of IE... :)
Check out your console output for errors. There will be some function that is not supported in ie 11
Unsupported querySelectorAll
Maybe unsupported classList property
Or maybe even forEach function
IE11 only support up to ECMAScript 5, whereas other more modern browsers use ECMAScript 6. They don't intent on updating it either.
ES 5 basically has less features for Javascript than ES 6, so that could be the culprit.
I like to use https://caniuse.com/ to see which functions are supported by which browser.
For example, it looks like querySelectorAll is supported by IE11:
https://caniuse.com/#search=queryselectorall
EDIT:
If you do wish to use ES6 features in IE11, you can have a look at BabelJS.
https://babeljs.io/
So, IE11 does not support forEach on a nodeList. I solved this problem by expanding the nodeList.prototype:
NodeList.prototype.forEach = Array.prototype.forEach;
I am using angularjs, and having problem with null assignment in safari only. Its working in chrome and firefox.
$scope.submit = function(id=null){
}
I am getting this error
SyntaxError: Expected token ')'
when I remove null, It just works. I don't know why !
$scope.submit = function(id){
}
Please help me to understand why this happening only with safari ?
Default parameters from ES2015 are not yet supported in Safari. Please check the compatibility table.
At the moment the basic support provide Chrome 49 and Firefox 15.
But you can use the following ES5 code to achieve the same:
$scope.submit = function(id) {
if (id === undefined) {
id = null;
}
}
I have a little problem, because I wrote my plugin using Object.create and it's working only on IE9+.
My plugin definition:
$.fn.MYPL = function (options) {
return this.each(function () {
myplg = Object.create(MYPL);
myplg.init(options, this);
});
};
But before every JS code I have the following:
if (typeof Object.create !== "function") {
Object.create = (function () {
function F() {} // created only once
return function (o) {
F.prototype = o; // reused on each invocation
return new F();
};
})();
}
It works fine on IE9+ but IE6 and IE7 (even IE8) seems to be not supporting Object.create or what? Am I missing sth?
Check Wikipedia's JavaScript version history. If you find 1.8.5 version - and this is the language version where you find this Object factory method available - 9th version of Internet Explorer is the one supporting that.
The ECMAScript 5 Compatibility Table also has this information.
You can also try for yourself using one of Microsoft's IE virtual machines (available from here or, for very old versions of IE, Multiple IE.
Sourced from From which version, IE can support Object.create(null)?
Older IE versions will not support Object.create. Read here https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/create
Try to create object using constructor which is described here https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Inheritance_and_the_prototype_chain
I am trying to call a custom method of an embedded flash like so:
var flash =
navigation_get_flash_movie_object('main');
if (flash) {
flash.continentOut(id); }
Which works great in Chrome ans Safari, but fails utterly in IE7 & IE8. The browsers throws an error that the object doesn't have such a method.
I am using the example from http://www.permadi.com/tutorial/flashjscommand/, and now that I've tested it, it also fails at it's testing page as well http://www.permadi.com/tutorial/flashGetObject/
Does anyone have a better way to invoke custom functions in a Flash object from Javascript?
Check out the ExternalInterface API Docs. They use this method:
function thisMovie(movieName) {
if (navigator.appName.indexOf("Microsoft") != -1) {
return window[movieName];
} else {
return document[movieName];
}
}
So you would do this:
var flash = thisMovie('main'); if (flash) { flash.continentOut(id); }
(I'm assuming of course that you're using ExternalInterface.addCallback() to define continentOut)
Here's another option:
function thisMovie(movieName) {
return document[movieName] || window[movieName];
}
Personally, this seems better because it doesn't use browser sniffing and would be future-compatible, but that's just me.