如何停止从浏览器调试我的js代码
function ViewSeatInfo(busNo, scheduleId, seatFare, tripType, dDate, time, numberOfSeat, seatUpdate, seatId) {
totalPrice = 0;
schedule_Id = scheduleId;
bus_No = busNo;
trip_Type = tripType;
d_date = dDate;
_time = time;
mainSeatId = seatId;
window.numberOfSeat = numberOfSeat;
window.seatUpdate = seatUpdate;
currentSell = 0;
var seats = "";
var data;
$.ajax({
type: 'post',
contentType: 'application/json; charset=utf-8',
url: "SellTicketOnline.aspx/ShowBusAndSeatInfo",
data: "{'busNo':'" + busNo + "'," + "'scheduleId':'" + scheduleId + "'}",
async: false,
success: function(response) {
data = response;
},
error: function() {
alert("error");
}
});
seatFare = data.d.BusMainFare;
seat_Fare = seatFare;
baseFare = seatFare;
ShowBusSeatAllocation(data, seatFare);
LoadStationByRouteId();
LoadBoardingPoint();
}
答案 0 :(得分:0)
网页的JavaScript在浏览器(客户端)中运行,意味着浏览器需要下载文件并执行,因此它必须能够访问"原始文件" JS文件。因此,您无法阻止其他开发人员查看您的代码。
您可以做的是让人们更难理解和调试您的应用程序。
可用的一些可能性是:
console.log()
之类的调试工具,例如:
(function() {
// disables the use of `console.log`, `console.info`, `console.error`, `console.warn` and others by replacing them with empty functions,
// this makes the use of the debugger harder.
var empty = function() {};
Object.keys(window.console).forEach(function(prop) {
window.console[prop] = empty;
});
console.log('log');
console.info('info');
console.error('error');
console.warn('warn');
})(window);

一些有趣的项目和文章:
https://github.com/javascript-obfuscator/javascript-obfuscator
How to prevent your JavaScript code from being stolen, copied, and viewed?