Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

153
Views
How can you use an attribute tag to insert a variable from local storage to run a script

I have my javascript stored in a localstorage varibale as hackVariable defined below. hackVariable
begin:
">document.querySelector('[onclick="Hackbutton()";]').click();<img src='notexist.png'
end:

Then I have this html doc with the goal to trigger the click button after the hackVariable has been put in alt attribute of the image tag. The issue I'm facing is that the browser interprets the " as " in the variable hackVariable.

<!DOCTYPE html>
<html>
<body>

<p>This example uses the HTML DOM to try to click a button</p>

<img src="winner.jpg" alt="hackVariable" width="100" height="100" >

<button  type="button" id="Hackbutton" onclik="DoSomethingCrazy()"> Click Me!</button>

</body>
</html>

This is the result I get

<img src="winner.jpg" alt=" &quot;><script>document.querySelector('[onclick=*&quot;*Hackbutton()*&quot;*;]').click();</script><img src='notexist.png' width="100" height="132" >

This is what I want to get

<img src="winner.jpg" alt=" "><script>document.querySelector('[onclick="Hackbutton()";]').click();</script><img src='notexist.png' width="100" height="100" >

My goal is to try to prevent the browser from encoding the double quote " coming from the variable into " I tried few methods like replacing the " with &x22 or &#34; but didn't work.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!