I am scraping results from a couple of websites, and presenting them as both a list and as markers on a map. Both list and map contain icons with links to individual result pages on the two sites.
Where results from both sites have the same geo-location both are shown. I want to open both links whenever one is clicked.
Links are served to the page in the form
this_json[n].ll = "<a class="link" href=https://www.someplace.com/this.html target=”p15”><img src=./require/images/icon1 alt="someplace"></a>"
this_json[n].ll2 = "<a class="link" href=https://www.somewhere.com/that.html target=”u12”><img src=./require/images/icon2 alt="somewhere"></a>"
I use the following code, which styles whichever link is clicked, as expected. However it only opens tab1, irrespective of which link icon is first clicked. The console logging shows that the script completes without problem but tab2 is not opened. If one of the link icons is subsequently clicked, it doesn't matter which, then tab2 is opened.
The wanted behaviour is that both tab1 and tab2 are opened on the first click, preferably with the focus going to whichever was clicked.
If there is only one link, this_json[n].ll2 is blank and the link opens as expected.
Ideally I want all links to open in named tabs in the same tab group in Chrome on Android. From my memory this used to work such that links all clustered in the same group and open tabs weren't repeated. Now they open as separate windows and will repeat, ie the target name is no longer respected, but I don't know how or why that changed.
var all_hrefs = document.querySelectorAll("a");
all_hrefs.forEach(function(single_href) {
single_href.addEventListener('click', function(){
this.classList.add('clicked');
fox = this
this_json.forEach(function(a_json) {
if (a_json.ll.includes(fox) || a_json.ll2.includes(fox)) {
partial1 = a_json.ll.split('http')[1].split('targ')
tab1 = 'http' + partial1[0]
name1 = partial1[1].split('=')[1].split('>')[0]
window.open(tab1, name1)
console.log('try ' + name1 + ' ' + tab1 ) // => try ”p15” https://www.someplace.com/this.html
partial2 = a_json.ll2.split('http')[1].split('targ')
tab2 = 'http' + partial2[0]
name2 = partial2[1].split('=')[1].split('>')[0]
window.open(tab2, name2)
console.log('try ' + name2 + ' ' + tab2 ) // => try "u12" https://www.somewhere.com/that.html
}
})
})
})