Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here is the code i used in my page.

XML
<script type="text/javascript">

window.onbeforeunload = function () {
    if (_clickedAnchor) {
        _clickedAnchor = false;
        return "Out Put Message";
    }
}

_clickedAnchor = false;

jQuery(document).ready(function () {
    jQuery("a").click(function () {
        _clickedAnchor = true;
    });
});

</script>



Error:-JavaScript runtime error: 'jQuery' is undefined
Posted
Updated 27-Jan-14 22:46pm
v2

1 solution

As it reads = you have no jQuery.
First add jQuery to your project using NuGet, than add jQuery to your page using <script></script> tag...

Add reference to jQuery package...
1. right click your project
2. select Manage NuGetPackage
3. select online
4. search for jQuery
5. hit install

Add jQuery to your page...
In the <head> of your page add line like this:
<script src="/js/jquery-1.7.1.js" type="text/javascript"></script>

Exact path and version can be different...
 
Share this answer
 
v2
Comments
ntitish 28-Jan-14 5:09am    
how to add jquery to my project sir....
Kornfeld Eliyahu Peter 28-Jan-14 5:16am    
See updated solution
ntitish 28-Jan-14 5:41am    
sir i had one doubt actually in that onbeforeunload function i want to show one alert and i want to stop redirecting to other page is it possible......

My code is like below


<script type="text/javascript">

var Level = '<%=Session["UserLevel"]%>'
if (Level == 3) {
var id = '<%=Session["uid"]%>';
if (id == 1) {

function get1() {

window.onbeforeunload = null;
}
window.onbeforeunload = confirmExit;
function confirmExit() {
alert("Please save offiec referral Befor you leave from this page");

}
}
}

</script>
Kornfeld Eliyahu Peter 28-Jan-14 5:45am    
If you want to stop then do return false from your confirmation function...
ntitish 28-Jan-14 5:48am    
if i written like that return false it is showing two popups one is simple alert and one more popup with options "leave this page" or "stay on this page"...but i need only alert...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900