Google chrome replaces C° with C° in javascript file - javascript

I tried to run my code in my google chrome browser (version:71.0.3578.98) on a local python https server but when I try to run it the "C°" is "C°". When I lock in the developer tools it is the same but in the code I have on my Desktop it's "C°" and not "C°".
I tried to use diffrent Browsers (FireFox, Opera) but nothing works.
I found out that when I download the chrome plugin (Set Character Encoding) and set the encoding to UTF-8 it works and there stands "C°"
but why is chrome this not doing by default
var temp = 5;
var str = "Now: " + temp + "C°";
console.log(str);
I expected that the chrome browser shows my "Now: 5C°" and not "Now: 5C°".

You could try to use the Hex value to see if it works:
var temp = 5;
var str = "Now: " + temp + "C\xB0";
console.log(str);
If i understood correctly your problem is explain here : http://mc-computing.com/languages/Javascript/Degree_Symbol/Degree_Symbol.html

Please check your character encoding in HTML <head> element.
Add following line in element of your webpage:
<meta charset="utf-8">

Related

Cookie from local homepage lost between sessions in Firefox 57

(Note: I believe I'm asking about the same problem as this unanswered question, which is less specific than mine partly because it didn't include an MWE. Per discussion on this meta page and this one, I believe it's OK to post a better version of an existing question that has not been answered.)
The following HTML contains an MWE version of a script that worked for years in Firefox but suddenly failed in Firefox 57.0. The MWE simply displays an integer, incrementing it each time the file is loaded. The script works in Safari, displaying a different integer each time if I set this file to load when Safari starts. It works in FF if I repeatedly load the file from the menu using File/Open in the same session. However in FF 57 it always displays 0 if I load the file when the browser starts. Examination of document.cookie and miscellaneous console.log() statements show that this happens because FF 57 loses the cookie between sessions. Why?
Is this a bug in FF 57? Is there something subtly wrong with my code that's causing it to fail in FF 57? Maybe because FF 57 is stricter about Javascript in some way? (I've checked to see if there's a report about this, but haven't found anything, and have checked to see any of the config settings in Preferences or in about:config that might control this behavior, but I haven't found anything.)
<html>
<head>
<script type="text/javascript">
<!--
function incrementCookie() {
lastfooStr = getCookie("foo");
if (lastfooStr == null || lastfooStr == NaN) { // if first time, start the indexes at 0
nextfoo = 0;
} else {
nextfoo = 1 + parseInt(lastfooStr); //increment it
}
setCookie("foo", nextfoo, 365);
document.write("<head><body>" + nextfoo + "</body></head>");
}
function setCookie(cookie_name, value, expire_days) {
var expire_date=new Date(); // get now
expire_date.setDate(expire_date.getDate() + expire_days); // expiration date
var cookie = cookie_name + "=" + value +
"; expires=" + expire_date.toUTCString() +
"; path=/";
document.cookie = cookie;
}
function getCookie(cookie_name) {
var doc_cookie = " " + document.cookie;
var cookie_value = null;
var cookie_start = doc_cookie.indexOf(" " + cookie_name + "=");
if (cookie_start != -1) { // found it; now get the value.
var cookie_val_start = doc_cookie.indexOf("=", cookie_start) + 1;
var cookie_val_end = doc_cookie.indexOf(";", cookie_val_start);
if (cookie_val_end == -1) { // must be the last cookie
cookie_val_end = doc_cookie.length;
}
cookie_value = doc_cookie.substring(cookie_val_start, cookie_val_end);
}
return cookie_value;
}
window.onload=incrementCookie();
//-->
</script>
</head>
</html>
Full disclosure: In FF 57, I get the following (irrelevant, I believe) messages in the console when I run this script:
An unbalanced tree was written using document.write() causing data from the network to be reparsed. For more information https://developer.mozilla.org/en/Optimizing_Your_Pages_for_Speculative_Parsing
cookietest.html:48
Line 48 is the second to last line of the file; it's the one containing the </script> tag.
And:
The character encoding of the HTML document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the page must be declared in the document or in the transfer protocol.
In Safari, I only get this message when I run it:
Not allowed to load local resource: file:///favicon.ico

FireFox document.exeCommand('copy') not working

I have the following code :
var doc = window.document;
var copyFrom = doc.createElement("textarea");
copyFrom.textContent = str;
var body = document.getElementsByTagName('body')[0];
body.appendChild(copyFrom);
copyFrom.select();
document.execCommand('copy');
body.removeChild(copyFrom);
This seems to work fine on Chrome as I am able to paste the contents on my 'str' variable. However this doesn't seem to work on FireFox/Safari.
Safari does not give clipboard access without user generated event. So only user initiated actions ( e.g Ctrl + C/ Cmd + C) can work to copy items.
About Firefox, can you give some details regarding the version. There has been a change post 44.0 where copy to clipboard has been enabled.

Download ICS String into Mobile with Javascript (Angularjs)

I'm creating a ics string in my app with this code:
var icsMSG = "BEGIN:VCALENDAR\nVERSION:2.0\nPRODID:-//Our Company//NONSGML v1.0//EN\nBEGIN:VEVENT\nUID:me#google.com\nDTSTAMP:" + today
icsMSG = icsMSG + "\nATTENDEE;CN=My Self ;RSVP=TRUE:MAILTO:me#gmail.com\nORGANIZER;CN=Me:MAILTO::me#gmail.com\nDTSTART:" + start +"\nDTEND:" + end +"\nSUMMARY:" + $scope.eventContent.text + "\nEND:VEVENT\nEND:VCALENDAR";
This is working fine, since when I want to download on my PC it works fine.
For downloading in PC I'm using
window.open( "data:text/calendar;charset=utf8," + escape(icsMSG));
Apparently this does not work on mobile. On iPhone it does not recognize the file, in Android it downloads the file and you must open it to add to calendar.
I read about webcal:// But it seems to not work sending the string after the webcal://
How can I set the download click in mobile
The spec-compliant newline sequence is \r\n. I doubt that's the problem, but you could try it.
Also, you could try charset=utf-8 (add the dash).
Also note that you have an extra colon character in one of your "mailto" URIs.

The offline version repl.it

Not sure if I am putting my question correctly - Is it possible to have an offline version of repl.it (only JavaScript required), so that it can be used without internet access?
If you're looking to install a way to run a JavaScript REPL on your local machine, you have two options:
Open your browser's console as usual. Lack of internet doesn't make it any less JavaScripty.
Install NodeJS
If you have a text editor that can run a dos command, you can use CScript.exe, the windows version of a javascript engine. Though beware, that this is not ES5 compatible, and there is no browser object. Writing to stdout can be done using CScript.Echo()
I use TextPad which has a tools configuration, in which you can set the CScript path (find it in your windows system directory).
I wonder why can't you do to create your own REPL instead, you just have to create a new window.open("", "_Jres", "", "false") you can also have window.open("", "_self") to replace the current document.
<!DOCTYPE html>
<html>
<head><title>Js Execute</title></head>
<body>
<textarea id="code" rows="10" cols="50">
//write your code here
alert("Clicking OK will write heading 1 in the new window");
document.write("<h1>heading 1</h1>");
</textarea>
<br/>
<button onclick="Execute()">Click To execute the above written JS</button>
<script>
function Execute() {
var win2 = window.open("", "_Jres", "", "false");
var content = document.getElementById("code");
var datacode = content.value;
console.log(datacode);
var hbody = "<script>" + datacode + "</" + "script>";
win2.document.writeln(hbody);
}
</script>
</body>
</html>

logStringMessage function inside Firefox extension

I was developing a small extension for Firefox. I wanted to log messages while a part of my extension is executing.
CODE:
var aConsoleService = Components.classes["#mozilla.org/consoleservice;1"].getService (Components.interfaces.nsIConsoleService);
aConsoleService.logStringMessage("created");
Here "created" is message. But I am unable to see this message inside browser console. Am I missing something? I searched for it and got to know that you have to enable devtools.errorconsole.enabled inside about:config. I did that too. Please help me out.
Are you sure you're opening the browser console? Ctrl + Shift + J?
var {utils:Cu, interfaces:Ci} = Components;
Components.classes["#mozilla.org/consoleservice;1"].getService(Components.interfaces.nsIConsoleService);
consoleService.logStringMessage(text);
also can try this:
var {utils:Cu, interfaces:Ci} = Components;
Cu.import('resource://gre/modules/Services.jsm');
Services.console.logStringMessage(text);
can also try this
var {utils:Cu, interfaces:Ci} = Components;
Cu.import('resource://gre/modules/Services.jsm');
Services.appShell.hiddenDOMWindow.console.log('blah');
if you're using addon sdk then instead of var {utils:Cu, interfaces:Ci} = Components; you have to do var {Cu, Ci} = require('chrome');

Categories