---
title: "如何中止javascript执行"
author: "bardo"
date: "2010-05-04T21:55:36Z"
tags: []
categories: ["Web前端"]
slug: "javascript"
draft: false
lastmod: "2010-05-04T21:55:36Z"
id: 659050
url: "https://bardo.iteye.com/blog/659050"
---

JS没有PHP的exit, 也没有JAVA的return。

如果JS代码不是函数，则需要中止JS执行时，只有一个办法，那就是：

document.location.href=your_url;

此外，throw虽能中止，但仍是不友好的出错信息，所以，如果想友好中止，只能是以上方法。

因此，非函数模式的代码，是无法停留在当前页面实现中止的。