I would like to do something like this:
console.log('Your server available at localhost:3000 ');
But unfortunately node console doesn't recognize 'a' tag.
Are any ideas how to put link in node console?
There is no way you can make an HTML tag interpreted by your the terminal, because your terminal has no ideas what html is.
You can just display a URL in console output like
console.log('Your server available at http://localhost:3000
Most modern terminals will automatically parse it as a URL (if you put a valid URL there)
For example, Mac default terminal redirects to valid URL from console output if you double-click on it while holding Cmd
console.log in Node renders text in the console window (command prompt in Windows) which does not know how to interpret html tags. I am afraid that you would not be able to do that unless you find a 3rd party plugin (if such plugin even exists) that allow that.
Hope that helps.
You don't need this. Some terminals started supporting links not long time ago. I think it was around 2017.
You will find more info here: https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda
Related
I wanna show some popup message from server side javascript(Node.JS) code.
exports.ShowPopup = function(req, res){
window.alert("Pradeep");
};
This was i tried. But while redirecting to this path i'm getting the error like
" window is not defined "
So can u please help me on this.Thanks in Advance.
With regards
Pradeep Raj. K
This is not possible. You cannot control the users browser with server side executed code.
I think you misunderstood NodeJS. NodeJS is a binary that runs javascript as server side code. It works just as any other scripting language on a server like Python or such.
You tried to use the window object, which is exclusive to the (or most) browsers API and does not exist in the regular Node environment. Also you don’t have any GUI, so you won't be able to accomplish what you are trying. Just use regular front end javascript for this.
PS: I assume you meant showing a popup in the browser, right?
I can't seem to find this problem anywhere else and I'm getting frustrated with it. Basically, I have whitelisted my device successfully and I am starting to develop a simple 'Hello World' application using Chrome as my sender. I went in and I whitelisted localhost in the Chromecast extension and added data-cast-api-enabled="true" to the html tag of my sender page. It even seems as if the extension is trying to inject the API.
But, in the Chrome debugger I get an error: Uncaught SyntaxError: Unexpected token ILLEGAL
I looked in the network tab and saw that api_script.js was coming in from the extension and I could even open it in a separate tab. But, for some reason this page is interpreting this javascript file as...well, what appears to be Japanese. In the network tab, the response for the request for api_script.js is (and this is just abbreviated):
....慶慣瑳㴠挠獡⁴籼笠㭽挊獡䅎䕍㴠∠慃瑳灁≩慣瑳嘮剅䥓乏㴠嬠ⰲ㐠㭝挊獡敒散癩牥㴠映湵瑣潩⡮摩慮敭
桴獩椮‽摩†桴獩渮浡‽慮敭†桴獩椮味扡牐橯捥整‽桴獩椮䅰摤敲獳㴠渠汵੬㭽挊獡慌湵档敄捳楲瑰潩‽畦据
湯⤨笠 琠楨牵‽桴獩琮硥⁴‽畮汬紊慣瑳䰮畡据剨煥敵瑳㴠映湵瑣潩⡮捡楴楶祴祔数敲散癩牥
†桴獩愮瑣癩瑩呹灹
‽捡楴楶祴祔数†桴獩爮捥楥敶‽敲散癩牥†桴獩搮獥牣灩楴湯㴠琠楨慰慲敭整獲㴠渠汵㭬 琠楨楤捳湯敮瑣潐楬
㴠∠潣瑮湩敵ਢ...
I'm not really sure why this is happening. It seems like copying the API code directly into my webpage is the only way I can get this thing working at all. Does anyone have any insight on this?
Chromecast is interpreting your script as UTF-16 (as proof, I pasted that garbage and saved it as UTF-16-LE, and got a text file starting with var cast = cast || {};).
Make sure you don't have a BOM header on the script. If the problem is due to charset detection, try adding some extended-ASCII characters in a comment near the beginning to force charset detection to pick e.g. UTF-8.
How can I open a URL from the command line script as a POST request to a URL? I'd like to to do this on Linux, Windows, and MacOS so a cross platform way of doing this
For each of these I can open a GET request to a URL using:
xdg-open [url] - Linux
start [url] - Windows
open [url] - MacOS
... but I don't see a way of doing a POST request. Is it possible, and if so how?
Also, showing how to add a POST body to the request would be appreciated too. Fyi, the script I'm writing is written in Ruby so anything built-in to the OS or something using Ruby is fine too.
UPDATED:
To clarify I'd like this open up in the default browser, not just issue the POST request and get the result.
Sorry, but there's no reliable way to do this across browsers and across operating systems. This was a topic the IE team spent a bunch of time looking into when we built Accelerators in IE8.
The closest you can come is writing a HTML page to disk that has an auto-submitting form (or XmlHttpRequest), then invoking the browser to load that page which will submit the form. This constrains your code to only submitting forms that are legal to submit from the browser (e.g. only thee possible content types, etc).
If you're using ruby you can use the NET::HTTP library: http://ruby-doc.org/stdlib-2.0/libdoc/net/http/rdoc/Net/HTTP.html
require 'net/http'
uri = URI('http://www.example.com/search.cgi')
res = Net::HTTP.post_form(uri, 'q' => 'ruby', 'max' => '50')
puts res.body
I don't know how compatible my solution is across browsers and platforms.
But instead of using a temporary file as described by #EricLaw,
you can encode that html with the auto-submit form in a Data URL, as i did here:
https://superuser.com/questions/1281950/open-chrome-with-method-post-body-data-on-specific-url/1631277#1631277
I'm trying to get the Spotify Hello World app running (https://developer.spotify.com/technologies/apps/tutorial/) and when I run the app in Spotify it doesn't load anything. Using the Inspector, it shows nothing in the head and body of the HTML. I've verified time and again that there actually is something in my index.html file.
I do have a developer's account and I am a premium member.
Does anyone have any suggestions for me to get the app to run correctly?
[SOLVED] I just realized when trying to load the application I was typing spotify:app:Tutorial when it should have been spotify:app:tutorial. It's case sensitive, yet when its the wrong case it doesn't yield any error, just empty HTML.
Seems like your application is found else you would get a not found error. At this rate we can't really tell alot. You might wanna include your manifest and index.html file.
Also if you change something in your manifest you have to kill spotify and restart for it to work properly again.
Using linux (Ubuntu 11.10) the tutorial did not start correctly until I used
consistent caps.
I.e. I changed to "tutorial" instead of "Tutorial" in both app directory name
and in the manifest. Still, the "Spotify" dir in $home needs S in caps.
Then the app started correctly using uri spotify:app:tutorial
I.e. ~/Spotify/tutorial/*
Make sure "BundleIdentifier":"tutorial" is in your manifest.json file.
I know there's a way for extensions and pages to communicate locally, but I need to send a message from an outside URL, have my Chrome Extension listen for it.
I have tried easyXDM in the background page, but it seems to stop listening after awhile, as if Google "turns off" the Javascript in the background page after awhile.
I think you may try some walk around and build a site with some specific data structure, and then implement a content script which will look for this specific that specific data structure, and when i finds one it can fetch the data you want to be passed to your extension.
Yes, you need a content script that communicates with the page using DOM Events.. Instructions on how to do that are here:
http://code.google.com/chrome/extensions/content_scripts.html#host-page-communication