Solved

jQuery before leaving a page (ASP MVC3 framework)

Posted on 2012-03-31
9
457 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Polygon I google maps 1 16
jQuery not working on ELSE... why? 2 24
using php variable inside javascript 5 15
how can apply the following conditionals: 5 21
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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…

867 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now