Skip to content
Advertisement

Alternative to window.open that doesn’t involve CORS

I have a page with a list of links that were set to open in new windows/tabs with target=’_blank’ and I wanted to give users a choice to load links in the same window so I’ve set up a checkbox to toggle the ‘newwin’ boolean and now open links with the following function

function dolink(myurl) {
if (newwin) { window.open(myurl, '_blank').focus(); }
else { window.open(myurl, '_self'); }
}

It works as expected but sets off all sorts of CORS stupidity now. In the first case it prints a message to the console that ‘Storage access automatically granted for origin “NEWSITE” on “MYSITE”’ which is bad enough and in the second case it stops resources loading on the new site due to CORS restrictions. Is there a better way to do this? I don’t want to join these sites to mine, just link to them.

Advertisement

Answer

Use a tag instead. Change the target attribute of a according to newwin.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement