-2

Is it possible to change a javascript variable through the URL?

Here's an example of the code I'm trying to modify from a website. (www.example.com)

<script type="text/javascript">

var x = 0;

</script>

I want to change the variable x from 0 to 1.

I want to do this by appending something to the URL. I'm not sure about the syntax, but I think it may be something like this:

www.example.com#javascript: var=1;

Is it possible to change variable x by only modifying the URL?

EDIT: The duplicate question doesn't tell me how (if it's possible) to change the variable through the URL. Please let me know if that's not the case.

Related Question: https://security.stackexchange.com/questions/134240/modify-javascript-variable-with-url-exploit

11
  • JavaScript on the page can look at window.location to decide what to do based on the URL. This requires the relevant JavaScript to already be present on the page. Commented Aug 18, 2016 at 17:02
  • That would be a serious security flaw, so browsers would not allow such a thing. If you control the JavaScript, you could (carefully) read part if the URL into a variable. Commented Aug 18, 2016 at 17:02
  • Please explain the reason for the downvotes. If you think it's a silly question, please just answer it. If it violates a site rule, please let me know. Thanks. Commented Aug 18, 2016 at 17:03
  • Please show an example URL from which you would like to retrieve/modify a variable, and show what the variable should become; without specifics this is a theoretical exercise and we're unable to offer any specific advice without guessing (which is of little use to you, and is too broad as a question). Incidentally I don't necessarily agree with the current close-reason, but unless you add some specifics the question is likely to remain closed, because we can't see that this question is not a duplicate. Or what this question is specifically asking. Commented Aug 18, 2016 at 17:06
  • Your questions shows a lack of research and is unclear. That's probably the reason for your down votes. Commented Aug 18, 2016 at 17:06

1 Answer 1

0

you can use:

 if(window.location.href.indexOf("your_link_to_check") > -1) {
      var x = 1;
    }
Sign up to request clarification or add additional context in comments.

3 Comments

Would it be possible to run this from the address bar in a browser? I'm pretty new to this area of programming. Thanks for your answer.
no, you can use Chrome's console to test it
What exactly would I put under "your_link_to_check"? Could you please clarify on that point?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.