0

I am trying to open a popup windows but the button's onclick content is stored in a variable. Thsi is my approach:

var page = 'window.open(\'ticket.html?wallet='+global_wallet+'\',\'popUpWindow\');';
document.getElementById('EditButton').onclick=page;

This is not working. Not popup being displayed. Something is missing and i don't figure out what is it...

Regards,

1 Answer 1

3

The onclick property is supposed to be a JavaScript function, not a string like you are trying.

You can pass a function:

document.getElementById('EditButton').onclick = function(){
    window.open('ticket.html?wallet='+global_wallet,'popUpWindow');
};

Or if for some reason you have to use the string, you can set the onclick attribute. In this case you need to use setAttibute() instead of the onclick property.

document.getElementById('EditButton').setAttribute('onclick', page);
Sign up to request clarification or add additional context in comments.

Comments

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.