代码之家  ›  专栏  ›  技术社区  ›  stephenmurdoch

强制显示模式内容的链接始终在当前选项卡中打开

  •  0
  • stephenmurdoch  · 技术社区  · 8 年前

    假设我有一个链接,可以打开包含一些文本的模式窗口。 我想阻止用户在新的浏览器选项卡中打开此链接。

    有没有一种方法可以说,即使用户明确要求在新的选项卡中打开该链接(即ctrl+click),该链接也应始终在当前浏览器选项卡中打开。

    我已经试过了 target='_self' 但毫无用处。

    1 回复  |  直到 8 年前
        1
  •  0
  •   stephenmurdoch    8 年前

    @gcampbell建议使用一个按钮,然后我记得我使用的框架(rails)有一个 button_to 生成以下内容的helper方法:

    = button_to "Say hello", contact_path, method: 'get', class: 'button', remote: true
    
    <form class="button_to" method="get" action="/contact-me" data-remote="true">
      <input class="button" value="Say hello" type="submit">
    </form>
    

    那就行了。谢谢@gcampbell,我完全不知道html按钮(和输入)有这种行为。