Q:

Modify Javascript Variable with URL Exploit

Is it possible to set a javascript variable through the URL?
Here's an example of the code I'm trying to modify:
<script type="text/javascript">

var x = 0;

</script>

Is there a way to modify that variable through a browser, for instance, www.somewebsite.com + (something that changes 'x' variable)?
Related on Stack Exchange:https://stackoverflow.com/questions/39023761/modify-javascript-variable-with-url

A:

No, this is not possible without an XSS vulnerability. If such a thing were generally possible, XSS would run rampant and you could execute any arbitrary code on any page, which would be bad.
Now if the code had a reflected XSS attack vector, or an DOM-based XSS attack vector, the the URL could be used to deliver a JavaScript payload. Of course, this would only be possible if the server-side or JavaScript code had such a security vulnerability (if your code makes that possible, then you should fix it).

