0

Is there a way to fire a Javascript function as soon as the user logs in. I am using asp.net authentication. When the user logs in, regardless from where i want to fire off JavaScript:Chat_OpenMessengerDialog(). This will open up my CuteSoft messenger window.

So i just want to automatically open the chat messenger when the user has logged in.

Any ideas?

Thanks

2
  • what have you tried so far? whats your HTML/JS? How does your login form work? are you logging the user in via ajax or via a post? are you using any JS libraries? Help us help you Commented Nov 1, 2010 at 0:54
  • I havent really tried anything because im at a loss at where it should be called from. The log in is done through a post through the default accountcontroller logon sub Commented Nov 1, 2010 at 1:26

2 Answers 2

1

One thing you could do is have in your master page a javascript block that will do exactly this but only be emitted to the client if IsAuthenticated is true.

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

1 Comment

+1 this is exactly what i do for a local message status callback plugin that needs the user to be logged PLUS i identify the roles as well and offer the functionality only to admin users. this is the opening code: <% if (Request.IsAuthenticated) { %> <% bool isSuperAdmin = ViewContext.HttpContext.User.IsInRole("SuperAdmin"); var userId = ViewData["UserGuid"];%> then the required javascript block is included, followed by the closing tag: <% } %>
1

Since you are doing the login via a Post to the controller, the javascript will need to be fired from the response that is returned from the post.

If the post returns a view, I would pass something to the view that tells it to fire the javascript. This can be a hidden field that the javascript looks for and then fires if found.

If the controller method returns a redirect, you can have the login method set something in Temp Data. Then you can use a base controller method to check for the temp data value on every request, if present, it can set some hidden field that the javascript looks for like in the previous scenario.

Comments

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.