简体   繁体   English

不涉及 CORS 的 window.open 替代方案

[英]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我有一个页面,其中包含设置为在新窗口/选项卡中打开 target='_blank' 的链接列表,我想让用户选择在同一窗口中加载链接,所以我设置了一个复选框来切换'newwin' 布尔值,现在打开具有以下功能的链接

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.它按预期工作,但现在引发了各种 CORS 愚蠢。 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.在第一种情况下,它会向控制台打印一条消息“自动为“MYSITE”上的“NEWSITE”授予存储访问权限,这已经够糟糕了,在第二种情况下,由于 CORS 限制,它会停止在新站点上加载资源。 Is there a better way to do this?有一个更好的方法吗? I don't want to join these sites to mine, just link to them.我不想将这些网站加入我的网站,只需链接到它们。

Use a tag instead.a标签。 Change the target attribute of a according to newwin .根据newwin更改atarget属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM