Skip to content

Instantly share code, notes, and snippets.

@mvcaaa
Created January 19, 2017 22:40
Show Gist options
  • Select an option

  • Save mvcaaa/b27d0d7e213e94ddd84a19142ff0bd6e to your computer and use it in GitHub Desktop.

Select an option

Save mvcaaa/b27d0d7e213e94ddd84a19142ff0bd6e to your computer and use it in GitHub Desktop.
<!--
/**
* Created by Astashov Andrey <[email protected]>
* Date: 20.01.2017 / 01:00
*/
-->
<script>
var objs = {
"1":{
"count":10,
"price":200
},
"2":{
"count":1,
"price":500
},
"16":{
"count":1,
"price":500
},
};
function summarize(objs) {
var sum = 0;
for (var i in objs) {
sum += objs[i].price * objs[i].count
}
return sum;
}
/**
* Этот код перестал работать в браузере chrome с 2016-06-02
* см. https://www.chromestatus.com/feature/5349061406228480
* Тестировать в EDGE/IE
* Переписать - гуглить спецификацию и как оно реализовывается.
*/
window.onbeforeunload = function () {
return "Summ is: "+ summarize(objs) + ". Continue ?";
}
</script>
<a href="#2">Link</a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment