【问题标题】:not open a href in the same window (javascript) [duplicate]不在同一窗口中打开href(javascript)[重复]
【发布时间】:2019-02-01 19:43:11
【问题描述】:

我的 jQuery 代码在新窗口中打开了这个 href。我想在同一个窗口中打开这个 href,但这不起作用。 (切换侧面)

jQuery('.dig-pub').on('click', function() {
  url = jQuery(this).parent().find('a').attr('href');

  // Remove this (opens new window)
  window.open(url);

  // Use below to open link in the same window
  //$(location).attr(url);

});

https://codepen.io/Kidkie/pen/gdaJjZ

【问题讨论】:

  • 试试这个window.open("https://www.youraddress.com","_self")
  • 试试window.location.href = url;
  • 请访问stackoverflow.com/questions/503093/…。希望对您有所帮助。
  • 使用window.location.href=url代码代替`window.open(url);

标签: javascript jquery html


【解决方案1】:

事实上,要在同一个窗口中打开 url,你可以像这样使用 window.location:

                jQuery('.dig-pub').on('click', function() {
                    url = jQuery(this).parent().find('a').attr('href');
                            window.location.href = url;
                                    });

【讨论】:

    猜你喜欢
    • 2010-09-21
    • 2014-08-01
    • 2018-03-03
    • 2011-06-06
    • 1970-01-01
    • 1970-01-01
    • 2018-04-05
    • 2023-02-26
    • 1970-01-01
    相关资源
    最近更新 更多