1

I'm trying to have Python run some Javascript, and I am running into a few issues. Namely that when I am trying to inject some text into a textarea of a page, it doesn't seem to work if and only if there is a newline (\n) as part of the variable inserted for the Javascript.

Here's my line:

br.runjs("document.getElementById('edit-body').value = '%s'" % (brag))

if the variable "brag" has any sort of newline in it at all, the insertion does not work. Any idea how to go around this?

1 Answer 1

2

Encode brag as JSON and then use that.

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

2 Comments

Do you have an example of how to do that? My Javascript is far less good than my Python, I can only do basic things (in order to interact with web pages). Working on picking up more, but still not there.
>>> print "var foo = %s" % (json.dumps('bar'),) var foo = "bar"

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.