I have the following code to get the link to bookmarking a topic on a phpBB forum
var bookmark = document.getElementsByClassName('bookmark-link');
console.log(bookmark)
var bookmark_array = Array.from(bookmark);
console.log(bookmark_array)
bookmark_array.length = 1;
console.log(bookmark_array)
var str = bookmark_array.toString();
console.log(str)
var link = str.match('\/viewtopic\.php\?f=(\d+)&t=(\d+)&bookmark=1&hash=(\w+)');
console.log(link)
window.open(link);
setTimeout(() => { window.close(link); }, 3000);
(console logs are just to visualize what's going on)
But window.open goes to a url like https://my.site.com/null in the end
The console log for link however shows the correct link I want to go to
When I execute it manually (copying the url from console.log(link) output, then doing window.open("what I copied") it works just fine
I assumed it's the issue with quotes, but enclosing link in them will result in https://my.site.com/"null"
I have popups enabled in Chrome for that site and it's whitelisted in all my adblockers.
So I'm really in the dark as to the reason why this happens
Thank you!
str.match()returns an array, not a string.Uncaught TypeError: Cannot read property 'toString' of null. I want to keep the code structure as is, since it's my first day coding in JS, so even though it's not very good at least I understand how it worksnull.bookmark_array[0].