在Safari iPhone的新标签页中打开链接 [英] Opening of links in new tab on Safari iPhone

查看:45
本文介绍了在Safari iPhone的新标签页中打开链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网站,可以帮助人们为自己的Instagram帖子创建标题并评估主题标签.其中一项功能很简单,只需将主题标签链接到Instagram,即可查看其中包含的图像类型.由于我不希望他们刚刚输入并评估为消失的输入,因此我使用target ="_ blank"在新标签页中打开了链接-这在台式机上效果很好,但在iPhone上,当您尝试单击该按钮时却没有任何反应标签链接.我怀疑通过禁用target ="_ blank"链接可以提供某种保护,但是我不确定.一切都只是简单的html链接.我尝试添加rel ="noreferrer",但这没有任何区别.

I have a site that helps people create captions for their Instagram posts and evaluate hashtags. One of the features is as simple as making links of the hashtags to Instagram in order to see what types of images they contain. As I don't want the input they have just entered and evaluated to disappear I have made the links open in new tabs by using target="_blank" - this works perfectly on desktops but on iPhones nothing happens when you try to click on the hashtag links. I suspect that it might be some sort of protection by disabling target="_blank" links, but I am not sure. Everything is just simple html links. I have tried adding rel="noreferrer" but that didn't make any difference.

因此,如果您对为什么它不起作用有一个解释,那将是有帮助的,而对我如何也能在移动设备上获得我想要的东西的解决方案更有用,那就是:打开一个链接到新标签中,这样我就不会丢失刚刚显示给用户的页面输入/状态.

So if you have an explanation as to why it does not work that would helpful, but even more helpful would be a solution as to how I can obtain what I want on mobile devices as well, which is simply put: open a link in a new tab so that I don't lose input/state of page that I have just presented to the user.

也非常赞赏上述问题的替代解决方案.

Alternative solutions to the above issue are also very much appreciated.

推荐答案

不推荐使用 dispatchEvent ,您可以使用:

as dispatchEvent is deprecated, you could use:

function openTab(url) {
  // Create link in memory
  var a = window.document.createElement("a");
  a.target = '_blank';
  a.href = url;

  //click
  a.click();
};

这篇关于在Safari iPhone的新标签页中打开链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆