0
<script>window.extractKey = 'value'</script>

I have to extract value of window.extractKey which is present in my html source code.

P.S.- I have to extract the value using javascript methods.

1 Answer 1

1

All script tags on a page have, and modify, the same window. It works fine:

<script>
  window.extractKey = 'value'
</script>

<script>
  const res = window.extractKey;
  console.log(res);
</script>

Sign up to request clarification or add additional context in comments.

3 Comments

I have to extract the value using javascript methods.
But why? There's literally no requirement to do so - it'll be available in any other script tag. You could select all tags, iterate through until you find one assigning that value, but...
I have a separate html file and I need to perform operation on that file and need to extract that value. That's why I need this using javascript method.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.