function-exit

Popup when leaving website

六眼飞鱼酱① 提交于 2020-01-01 18:17:06
问题 I got a problem with JavaScript. I want a script that will pop-up on exit whole web-site a message with question and if visitor answers "NO" web page closes and if he answers "YES" he will be redirected to another page. I found a example at http://www.pgrs.net/2008/01/30/popup-when-leaving-website/ but it seems that it doesnt work for me. I couldnt find any solution. Pleae check my code and tell me maybe i'm doing something wrong ? Here`s my source code. Maybe somebody will see a problem. <

What to put in the IF block and what to put in the ELSE block?

[亡魂溺海] 提交于 2019-12-18 15:03:18
问题 This is a minor style question, but every bit of readability you add to your code counts. So if you've got: if (condition) then { // do stuff } else { // do other stuff } How do you decide if it's better like that, or like this: if (!condition) then { // do other stuff { else { // do stuff } My heuristics are: Keep the condition positive (less mental calculation when reading it) Put the most common path into the first block 回答1: I prefer to put the most common path first, and I am a strong

Popup when leaving website

笑着哭i 提交于 2019-12-04 17:34:21
I got a problem with JavaScript. I want a script that will pop-up on exit whole web-site a message with question and if visitor answers "NO" web page closes and if he answers "YES" he will be redirected to another page. I found a example at http://www.pgrs.net/2008/01/30/popup-when-leaving-website/ but it seems that it doesnt work for me. I couldnt find any solution. Pleae check my code and tell me maybe i'm doing something wrong ? Here`s my source code. Maybe somebody will see a problem. <!DOCTYPE html> <html lang="lt"> <head> <meta charset="utf-8"> <title>PUA.LT</title> <meta http-equiv="X

What to put in the IF block and what to put in the ELSE block?

五迷三道 提交于 2019-11-30 11:48:15
This is a minor style question, but every bit of readability you add to your code counts. So if you've got: if (condition) then { // do stuff } else { // do other stuff } How do you decide if it's better like that, or like this: if (!condition) then { // do other stuff { else { // do stuff } My heuristics are: Keep the condition positive (less mental calculation when reading it) Put the most common path into the first block I prefer to put the most common path first, and I am a strong believer in nesting reduction so I will break, continue, or return instead of elsing whenever possible. I

Why is “else” rarely used after “if x then return”?

こ雲淡風輕ζ 提交于 2019-11-28 16:38:07
This method: boolean containsSmiley(String s) { if (s == null) { return false; } else { return s.contains(":)"); } } can equivalently be written: boolean containsSmiley(String s) { if (s == null) { return false; } return s.contains(":)"); } In my experience, the second form is seen more often, especially in more complex methods (where there may be several such exit points), and the same is true for "throw" as well as "return". Yet the first form arguably makes the conditional structure of the code more explicit. Are there any reasons to prefer one over the other? (Related: Should a function