I want to write JavaScript code and to use it in Python+Selenium script. Target URL is Microsoft account login page. Here I want to force onclick opening Terms of use page not in new tab, but in new window so I made some changes to appropriate anchor tag. I have a little experience in JS, so this is what I got for now:
document.querySelector('a#ftrTerms').setAttribute("onclick", "window.open('https://login.live.com/gls.srf?urlID=WinLiveTermsOfUse&mkt=EN-US&vv=1600', '', 'width=800,height=600')")
document.querySelector('a#ftrTerms').removeAttribute('href')
...and this works fine (not the best way, but it's ok). However, redirection URL is hardcoded, so I use following to get URL from href first and then pass it to attribute:
var reference = document.querySelector('a#ftrTerms').getAttribute('href');
document.querySelector('a#ftrTerms').setAttribute("onclick", "window.open(\'' + reference + '\', '', 'width=800,height=600')")
document.querySelector('a#ftrTerms').removeAttribute('href')
...and this code is not working: my attribute in HTML appears like
onclick="window.open('' + reference + '', '', 'width=800,height=600')".
So how to substitute reference name with its actual value?