javascript - 弹出窗口链接在窗口以及浏览器选项卡中启动
问题描述
我正在开发一个使用 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>
当我单击按钮时,弹出窗口工作正常,但链接也会在我单击它的选项卡中打开,但我不希望它打开。有没有办法做到这一点?
解决方案
我猜ui-sref
还会绑定一个点击事件,并且该事件将在您之前触发。
您可以跳过 ui-sref 并将 url 放在数据属性中或 onclick 属性中。您可以改为使用 $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的文档。
推荐阅读
- vuejs3 - Vuex4 和 Vue3 - Devtool 中未更新的状态
- javascript - watchMedia(或innerWidth?)作为显示div的mediaQuery
- node.js - firebase - 从可调用的云函数访问数据库时应用检查失败
- git - 终端中git返回的这张人图是什么意思?
- openid - 伪装的身份验证响应(OpenID Authentication 2.0)可以检测到吗?
- c# - 在 wpf 中的自定义样式上,文本框的文本始终为空
- postgresql - Nest JS - 有没有办法创建自定义数据库字段
- nuxt.js - 为什么输入类型是数字时可以输入字母“e”
- json - PL/SQL json_table 函数为大型 JSON 文档提供错误
- python - 如果条件匹配,则从第二个数据帧中获取数据并将其附加到第一个数据帧