How to show popup message using Node.JS - node.js

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?

Related

Spectron: how to test Electron `shell.openExternal('some url')`

I'm writing and E2E test for an application written in Electron. I need to test a button which calls in effect shell.openExternal('link') where link is an external website. I've been looking in the webdriver docs for something which allows the test intercept this call, but it doesn't look like anything like that exists in the API at all.
1) if something like this does exist an I missed it in the docs, please enlighten me in ways of the light side of the force,
2) if not, then does anyone out there in stackoverflow land have a fancy work-around?
Thanks so much!
I came up with an answer. Instead of trying to intercept the click, I added an env var in the main app such that when set, the click will put an entry into the log instead of actually opening the external link in a browser. Then I use the API in spectron to slurp up the render process logs: https://github.com/electron-userland/spectron#clientgetrenderprocesslogs
Then I can just look for a custom string in the logs and I can judge the proper text is present.

How to run server.js on client-side?

Can anyone explain me how I can run the server.js on client-side. Like I have index.html page and I've a button in it and I want to generate PDF on button click event and pass dynamic data to PDF. I've literally no idea about node.js. Any kind of help is appreciated. Sorry if the question is duplicate.
The simple answer is you don't. Node.js is a back end and the server.js file you have should not run on the browser. If you need the functionality on server.js after the first load you need to use something like ajax to communicate with the server. Or you could try to get your server code to run in the browser, but that may not work for all browsers and is probably a bad practice.

Put link in console.log(). Node.js

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

URL displays the source code

in my application particular URL displays the JavaScript source used in our project.For >https://example/faces/scripts/NameofJavaScript.js. It displays the java script mentioned in the URL as save or open option.please let me know about this issue.Is it Web server side issue or Application side issue.how to resolve this issue.I am using Java with Jsf. Thanks in advance.
You can't stop people from viewing your JavaScript code sadly; as it's a client side language, however if you were to use PHP or ASP.Net for example, the code would be hidden as it's server side.
Client Side - View able
Server Side - Hidden
Basic rules I go by anyway

Is it possible to detect Internet Explorer Enhanced Security Configuration in javascript?

Is there any method to tell from javascript if the browser has "enhanced security configuration" enabled?
I keep running into problems with certain controls not working from within dynamically loaded content. This only happens with browsers running on Windows Server 2003/2008 systems - even when I add the server to the "trusted" zone.
Maybe somebody has already develoepd a method for accomplishing this task?
Thanks in advance
Instead of testing for IE ESC directly, we can test for its effects.
I found that with ESC enabled the onclick events of dynamically added content would not fire.
So I am testing those events directly.
var IEESCEnabled = true;
var testButton = $("<button style=\"display: none;\" onclick=\"IEESCEnabled = false; alert('No problems here.');\">Test IE ESC</button>");
testButton.click();
if (IEESCEnabled) {
alert("We have a problem.");
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
In my application a test like this forwards the user to a page explaining their issue. It is accompanied by a noscript element to check that they have JavaScript running at all.
I don't think it's possible, and if it still is, than that's a bug that might sooner or later be fixed.
One of the main points of this "extra security" was for the client to have it but not to be detected by the servers, thus leaving them no way to know when to try to circumvent it and when not.
Isn't javascript disabled when using enhanced security configuration?
Then if you only want to display a message to the user, simply display a message in normal html and hide it with javascript so only users without javascript will see it. If you need to handle it on the server side (e.g. outputting a differerent version of your website) simply include javascript to redirect users to your javascript enabled version. Users without javascript will remain on the non-js page.
If only scriptable activex are disabled, the same method applies, simply insert a activeX and try to "script" it, if it fails you can redirect, show a message etc.
The above of course doesn't detect enhanced security configuration per se, but the symptons that occur when it is enabled. So it probably wouldn't be able to distinguish between users with using enhanced security configuration and users that simply have JS/ActiveX disabled or use a Browser that doesn't support scripting in the first place.
I think you can look for SV1 in the user agent string.

Resources