Popup window link launching in window as well as in the browser tab

2.6k Views Asked by At

I'm working on a website built using Laravel and AngularJS. I want a certain link to open in a popup window. The javascript code is

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?

2

There are 2 best solutions below

7
becquerel On BEST ANSWER

I would guess ui-sref will also bind a click-event and that event will trigger before yours.

You could skip the ui-sref and put the url in a data-attribute or inside the onclick-attribute. You could get the url using $state.href() instead. Then the problem may disappear.

Edit

You could bind it to a scope function and skip onclick all toghether. Something like this:

In the Controller (Also make sure you include $state in the controller first):

$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:

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

Also see documentation for state.href.

0
Amirah Aldarwish On
    <!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