简体   繁体   English

在窗口以及浏览器选项卡中启动的弹出窗口链接

[英]Popup window link launching in window as well as in the browser tab

I'm working on a website built using Laravel and AngularJS. 我正在使用Laravel和AngularJS构建的网站上工作。 I want a certain link to open in a popup window. 我想在弹出窗口中打开某个链接。 The javascript code is javascript代码是

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

and the link is 链接是

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

when I click on the button the popup works fine but the link also opens up in the tab where I clicked it, but I don't want it to. 当我单击按钮时,弹出窗口可以正常工作,但是该链接也会在我单击它的选项卡中打开,但我不希望这样做。 Is there a way to do it? 有办法吗?

I would guess ui-sref will also bind a click-event and that event will trigger before yours. 我猜ui-sref也将绑定一个click事件,并且该事件将在您之前触发。

You could skip the ui-sref and put the url in a data-attribute or inside the onclick-attribute. 您可以跳过ui-sref并将url放入数据属性或onclick属性内。 You could get the url using $state.href() instead. 您可以改为使用$ state.href()获取url。 Then the problem may disappear. 然后问题可能会消失。

Edit 编辑

You could bind it to a scope function and skip onclick all toghether. 您可以将其绑定到范围函数,并一起跳过onclick。 Something like this: 像这样:

In the Controller (Also make sure you include $state in the controller first): 在控制器中(还要确保首先在控制器中包含$ 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()}
}

And in the HTML you invke the popuitup function with the state name and its parameters: 在HTML中,使用状态名称及其参数调用popuitup函数:

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

Also see documentation for state.href . 另请参阅state.href的文档。

    <!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>

try this code for popup window and change google.com to you site 在弹出窗口中尝试使用此代码,并将google.com更改为您的网站

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM