Solved

jQuery before leaving a page (ASP MVC3 framework)

Posted on 2012-03-31
9
460 Views
Last Modified: 2012-04-12
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.

Thanks,

-Jeff
0
Comment
Question by:jeffiepoo
  • 4
  • 2
9 Comments
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 500 total points
ID: 37792546
You need to change the default behaviour of a link
http://api.jquery.com/animate/

$('#clickme').click(function(e) {
  $('#book').animate({
    opacity: 0.25,
    left: '+=50',
    height: 'toggle'
  }, 5000, function() {
    location = $(this).attr("href");
  });
  return false;
});
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 37792553
That will likely leave the page immediately!
0
 
LVL 6

Author Comment

by:jeffiepoo
ID: 37819017
I've requested that this question be deleted for the following reason:

No solutions, and this wasn't helpful
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 37818363
"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?
0
 
LVL 21

Expert Comment

by:Dale Burrell
ID: 37819018
Mplungjan suggestion is certainly a good starting point, and without additional feedback could easily be the solution. Points should be awarded.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 37819031
I am fine with no points, but the closing comments was not very nice.
0
 
LVL 21

Expert Comment

by:Dale Burrell
ID: 37840216
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developer portfolios can be a bit of an enigma—how do you present yourself to employers without burying them in lines of code?  A modern portfolio is more than just work samples, it’s also a statement of how you work.
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question