Home > OS >  Javascript: How to extract the onclick function in a button to text?
Javascript: How to extract the onclick function in a button to text?

Time:01-25

I've targeted a button and the onclick attribute contains a function call with a huge js/json object as its argument.

Inside that object, there is a url that I can extract, if I can just turn the .onclick value into a plain text string.

How to do?

CodePudding user response:

The getAttribute method will let you read a string value from an element's attribute (whereas the onclick property will give you a function).

If you have control over the site then it would probably be better to do some refactoring and move the URL into a data-* attribute which you can access from both the onclick script and the other script.

CodePudding user response:

It would be nice if you included your code. However, normally onclick calls take an event as argument. Inside of it, you can find your url.

  • Related