jQuery before leaving a page (ASP MVC3 framework)

Hey Experts,

I was wondering if it is possible to make some jQuery code run on the current page when a link to another page is clicked.

For instance, I have a menubar, and when someone clicks a link to another page, I want some elements to float off of the current page with jQuery's animate method before the other page loads.

I'm using the ASP.NET MVC3 framework.

Is it possible to do this?

Also, is it possible to change the javascript methods that are run depending on which page is going to another page? For instance, some code will only run if the person is on the home page and is loading the Contact page.


Who is Participating?
Michel PlungjanConnect With a Mentor IT ExpertCommented:
You need to change the default behaviour of a link

$('#clickme').click(function(e) {
    opacity: 0.25,
    left: '+=50',
    height: 'toggle'
  }, 5000, function() {
    location = $(this).attr("href");
  return false;
Michel PlungjanIT ExpertCommented:
That will likely leave the page immediately!
jeffiepooAuthor Commented:
I've requested that this question be deleted for the following reason:

No solutions, and this wasn't helpful
7 new features that'll make your work life better

It’s our mission to create a product that solves the huge challenges you face at work every day. In case you missed it, here are 7 delightful things we've added recently to monday to make it even more awesome.

Michel PlungjanIT ExpertCommented:
"No solutions, and this wasn't helpful" - was even less helpful.

Perhaps you could respond to suggestions detailing the issue you have with the code and we can help you better?

Did you even try my suggestion?
Dale BurrellDirectorCommented:
Mplungjan suggestion is certainly a good starting point, and without additional feedback could easily be the solution. Points should be awarded.
Michel PlungjanIT ExpertCommented:
I am fine with no points, but the closing comments was not very nice.
Dale BurrellDirectorCommented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.