【问题标题】:Popup window link launching in window as well as in the browser tab弹出窗口链接在窗口以及浏览器选项卡中启动
【发布时间】:2018-12-16 18:16:30
【问题描述】:

我正在开发一个使用 Laravel 和 AngularJS 构建的网站。 我想在弹出窗口中打开某个链接。 javascript代码是

function popitup(url) {
    newwindow=window.open(url,'test','height=400,width=550');
    if (window.focus) {newwindow.focus()}
    return false;
    }

链接是

<a ui-sref="test({id:test.id})" class="btn btn-primary fright" onclick="return popitup(this.href)" oncontextmenu="return false;">Resume</a>

当我单击按钮时,弹出窗口工作正常,但链接也会在我单击它的选项卡中打开,但我不希望它打开。 有办法吗?

【问题讨论】:

标签: javascript angularjs angular-ui-router popupwindow ui-sref


【解决方案1】:

我猜ui-sref 也会绑定一个点击事件,并且该事件会在你之前触发。

您可以跳过 ui-sref 并将 url 放在 data-attribute 或 onclick-attribute 中。您可以改为使用 $state.href() 获取 url。那么问题可能会消失。

编辑

您可以将其绑定到范围函数并一起跳过 onclick。像这样的:

在控制器中(还要确保首先在控制器中包含 $state):

$scope.popitup = function(stateName, options) {
 var url = $state.href(stateName, options);
 newwindow=window.open(url,'test','height=400,width=550');
 if (window.focus) {newwindow.focus()}
}

然后在 HTML 中调用带有状态名称及其参数的 popuitup 函数:

<a ng-click="popitup('test', {id:test.id})" 
   class="btn btn-primary fright" oncontextmenu="return false;">Resume</a>

另请参阅state.href 的文档。

【讨论】:

  • 那么我是否通过 $state.href() 中的 "test({id:test.id}) ?
  • 我认为你应该使用 ng-click 实际上。当我在电脑上而不是手机上时,让我更新我的答案。
  • 我将 $state 添加到控制器中,复制了其中的函数并修改了超链接,但单击它没有任何反应
  • 检查控制台。我刚刚看到我拼错了function。会这样吗?
  • 我在复制后立即纠正了它。控制台也没有显示任何问题
【解决方案2】:
    <!DOCTYPE html>
<html>
<body>


<a href="http://google.com" onclick="javascript:void window.open('http://google.com','example','width=700,height=500,toolbar=0,menubar=0,location=0,status=1,scrollbars=1,resizable=1,left=0,top=0');return false;">Popup-window</a>


</body>
</html>

试试这个代码弹出窗口并将 google.com 更改为您的站点

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-10
    • 1970-01-01
    • 2020-06-01
    • 2012-03-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多