开发者

Silly Javascript Help

var showPop = true;
function exitIt(){ 
     if (showPo开发者_如何学Pythonp){ 
     showPop = false;
     return 'blah blah';
     }
}

This is a little exit pop up. If the user chooses to "stay on the page", I need it to redirect to the proper URL. How can I do this?


Just because you can implement something, doesn't mean that you should. Exit popups are arguably the most annoying thing ever!


or document.location = "http://www.example.com/";


  if (confirm('Move to another page?')){ 
    window.location = "http://blah.com/";
  }


    $("a#myleavinglink").click(function() {
        var answer = confirm("Are you sure you should leave? Its so sweet thougH!");
        if (answer) {
            return true; 
        } else {
            return false;
        }
    }

You could also do a very similar thing with jQuery and if the user decides to leave the page, or back up, or type in their own address.

BTW, by returning true from a click function in jQuery will allow standard operations, but returning false will override the standard functionality and only provide the functionality you have choosen. Hence, if the user wants to leave, it returns true, else it returns false

$("a").live("click", function() {
    var id = $(this).attr("id");
    if (id == approvedClicks) {
        return true;
    } else {
        return false;
    }
});

that would prevent any links being clicked to be removed, whether at page load, or added in with JS.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜