[Javascript] How to print a variable to Linux console?
Declared as a global variable in an HTML file:
Code:
var pointsArray = new Array(); Code:
System.out.write (pointsArray.length); |
Hi -
I think I mentioned this in a previous post: Quote:
The most common equivalent of "printf()" in Javascript is "alert()". 'Hope that helps .. PSM |
Quote:
|
You also posted this question to Stackoverflow. I've answered it there.
Like other's. I'm curious as to where the System.out.write came from. |
Quote:
I am using Javascript for the Google API, and as we are supposed to search before asking, I looked up Google and found system.out mentioned somewhere w.r.t the same! Had I known Java, I would have known that system.out in specifically in Java! and all this is not a lie, and at the same time I wonder why no one corrected me on Stackoverflow. This question was there for past two days! No one answered there so I had to ask here. Quote:
Quote:
|
More things about Javascript.
It is also basically type less and only the client (browser) setting controls the fact that the error was ignored. So during development, you set it the client to display all script errors and abend. |
Quote:
I wanted it to display on "console". I am running the qt executable as "./showmap" and then a widget gets displayed on which the map is shown. On a button click, a function gets called and in that function I have written document.write("11"); which doesn't seem to be doing anything normal. |
Quote:
|
Quote:
But my question is how should I "print a variable" on the "Linux console" from Javascript functions. I am not talking of error messages here, I just want to see what the variables contain. Pardon if I have missed some point. Meanwhile I found this thread: http://stackoverflow.com/questions/1...-error-console Code:
var d = "Dugan" and in the first answer they talk about installing something called firebug, why it is so difficult to print something on the console, I wonder :mad: |
Quote:
Not an option in your case though, because you're not using Firefox. Now, if you had made it a functional requirement to write to the Linux console from browser-based Javascript, then you didn't think things through. There is absolutely nothing in either the ECMAScript standard or in any brower's DOM that would make this possible, and browser-based Javascript is specifically designed to run in a sandboxed environment with as few privileges as possible. Exactly why do you think that it would give you access to the operating system's standard output? In a normal browser, your options are the aforementioned alert and console.log. The second of these, console.log, writes not to standard output ("the Linux console") but to a part of the browser called the Javascript Console. That is what the Stackoverflow thread you linked to was talking about. Anyway, I would have thought that overriding javascriptConsoleMessage and then using console.log would have worked. But if you already tried it, then I guess not. |
Alright, but there must be some way to see what's in the javascript variables when working with Qt, I hope I am not the first person to be wanting the same! I mean what is the way to debug the logic of the Javascript program when working with Qt?
alert of course works, but I don't consider it nice to go clicking on "ok" buttons every now and then, especially when a loop goes on. Quote:
and editing your posts with important infos after long durations is not very helpful since it can be easily missed (no additional mail notification gets sent). |
Now I tried the console.log too as follows, and this worked flawlessly!
Code:
var d = "Dugan"; |
Have you tried overriding QWebPage::javascriptAlert to have it write to the Linux console (using qDebug), and then calling alert?
|
Quote:
|
Glad to hear it. I've edited my Stackoverflow reply to make it complete.
|
All times are GMT -5. The time now is 12:13 AM. |