Solved

jQuery before leaving a page (ASP MVC3 framework)

Posted on 2012-03-31
9
454 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
This article discusses how to create an extensible mechanism for linked drop downs.
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

706 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