0

Is it possible to pass in methods instead of just objects in an Express route?

For example, after redirecting to a specific route, I want to execute an alert function.

app.get(res.redirect('/', function(req, res){
   alert('this is an alert');
   });
);

console.log - seems to be ok, but other methods are not.

I have tried:

res.redirect('/');
alert('this is an alert');

same thing error: ReferenceError: alert is not defined

As, answered below that Alert is a Client side function and not a server side function:

Is there a way that I can tell the server side to pass some client side function after redirecting?

1
  • Please read how to ask. What exactly is the error? Commented Mar 1, 2016 at 21:07

1 Answer 1

4

The reason this doesn't work is because node.js and express are on the server side. The alert function has to be executed from the browser as it is a property of browser window objects.

See Node.js Alert Causes Crash

Sign up to request clarification or add additional context in comments.

2 Comments

Just to add more details: alert is a function of the browser's Window object. Node has no such Window object
Is there a way that I can tell the server side to pass some client side function after redirecting?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.