Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

jQuery before leaving a page (ASP MVC3 framework)

Posted on 2012-03-31
9
459 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
This video teaches users how to migrate an existing Wordpress website to a new domain.
The viewer will learn how to count occurrences of each item in an array.

791 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