I am taking a user input in C++ code and passing it into a JS function. It's causing XSS. The code below is a simplified version of the problem. If you run it, it will show an alert. Will HTML encoding fix it or is there any other encoding for this scenario?
<html>
<head>
<SCRIPT language="javascript">
function f1(id1, id2, flag){}
<!-- alert(1) is user input that was passed into this function -->
f1(768, alert(1), true);
</SCRIPT>
</head><body></body></html>