toLocaleString() doesn't work in Safari browser - javascript

I used toLocaleString() method to input money comma in `javascript. But the problem is, IE and chrome browser result correctly except Safari browser. I delete cache several times but still doesn't work.
var test = 12300;
console.log('test:'+test.toLocaleString());
// 12,300 in IE,Chrome
// 12300 in Safari

The issue here is that number.toLocaleString is implemented differently on different browsers. On Safari, it chooses not to display with the person-friendly formatting we're used to. It is supported on safari, but its implementation isn't the same as IE, Chrome, or Firefox. See this link: http://forums.asp.net/t/2031925.aspx?toLocaleString+function+is+inconsistent+with+browser+
Also, Safari doesn't support using the locale parameter with toLocaleString, in case you tried setting that:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString

Related

How to use scrollTop prop in Safari

Looking in this site I see in the browser compatibility section, it looks like this
What does that mean? What do I have to do to use that property in safari?
If I go element.scrollTop, that works just like that?
Webkit is the browser engine used by Safari and Chrome, the mentioned item in MDN it's only to clarify that all versions in Safari that use webkit (since like forever) support the property perfectly.
Nothing to worry about, just use it wisely as you would with any other modern browser

Is IE11 really not compatible with getNamedItem() JS function?

I'm trying to use getNamedItem() function. I can correctly access items using Chrome, Firefox, IE9 and IE10 ... but not when using IE11.
According to this, it seems expected : http://www.w3schools.com/jsref/met_namednodemap_getnameditem.asp
My question is : do we have an equivalent function which could be used in order to work with IE11 ?
getNamedItem() is supported in IE9+, including IE11.
Try this in IE11.

How to detect old Opera via JavaScript (non-Webkit, non-Next, version 14-)

Non-Webkit Opera was very specific in some features, so it was usually detected via JavaScript the following way.
However, Opera Next seeps to be almost a Google Chrome clone.
How can I target old Opera and not target Opera Next?
PS: I really do know that browser detection sucks and feature detection rules. But I hope to update the big and running project with a tiny browser-detection-patch rather then to rewrite tons of code into feature-detection paradigm.
I have found the problem source. It was in bad browser detection in that project. If you detect Opera exactly like in the link given in the question, Opera Next is not detected to be Opera, so Old-Opera-Specific code is not executed, and Chrome-Specific-Code runs instead.
!!window.opera; // true in old Opera, false in Opera Next
navigator.userAgent.indexOf("Opera");// ------- the same --------
PS: Fortunately, I have lots of tests on my project, so I can tell that in new Opera things are working exactly as in Google Chrome.
A piece of code that caused problems tried to detect Opera Old AND Opera Next:
/(Opera|OPR)/.test(navigator.userAgent)
Conclusion: Opera migration was made very well, nothing should break in your projects. Do not detect Opera Next and simply treat it as usual Google Chrome.
UPDATE: previous Opera versions had gone from caniuse.com

New Window in GWT, DOM, Internet explorer

I'm trying to create new Window with GWT as it shown here: https://stackoverflow.com/a/4205058/898588
This works in FF, Chrome, but doesn't work in IE (IE9 in my case). I see exception in dev. mode:
(null): DOM Exception: HIERARCHY_REQUEST_ERR (3)
So, this string:
bdElement.getOwnerDocument().getElementById("mainbody").appendChild(config.getElement());
throws this exception.
I've tried:
bdElement.appendChild(config.getElement());
but it was unsuccessfully.
How to make it work in IE?
Solution was found:
bdElement.getFirstChildElement().setInnerHTML(config.getElement().getString());
This works in IE, Opera, Chrome, FF
To be more specific, you only need to use setInnerHTML() instead of appendChild(), so the following piece of code will work as well in IE9 and Chrome as far as I can tell:
bdElement.getOwnerDocument().getElementById("mainbody").setInnerHTML(config.getElement().getString());

onbeforeunload in Opera

I'm using the code that netadictos posted to the question here. All I want to do is to display a warning when a user is navigating away from or closing a window/tab.
The code that netadictos posted seems to work fine in IE7, FF 3.0.5, Safari 3.2.1, and Chrome but it doesn't work in Opera v9.63. Does anyone know of way of doing the same thing in Opera?
Thx, Trev
Opera does not support window.onbeforeunload at the moment. It will be supported in some future version, but has not been a sufficiently high priority to get implemented as of Opera 11.
onbeforeunload is now supported in Opera 15 based on the WebKit engine but not in any prior versions based on Presto.
Have you tried this?
history.navigationMode = 'compatible';
Reference, found via this page
I haven't actually tried it myself, but it looks promising.
Mobile Safari (iPhone/iPad) also doesn't support onbeforeunload, and I strongly suspect it is not likely to.
For detecting back/forward navigation there may be workarounds e.g. see Is there an alternative method to use onbeforeunload in mobile safari?.

Categories