Href in javascript

0

Let's see if I explain ...

I have a view in which I have a href that is given by a javascript function that I have in a .js file.

The fact is that the link is perfectly generated, simply the javascript function has a

window.location.href = "link que se genera"

When you click with the left button the link opens in the same window and tab, but if you hit the right button - > open in a new tab this is what happens:

  

about: blank

in principle I do not have any prevent or anything so it should not be interfering with the clicks and I do not manage them in any way since it generates a normal url.

Any ideas?

The code is more or less this

In the view:

<a rel="nofollow"  href="javascript:link.Generator.go('<?echo$pageId?>')" class="automatic"></a>

And the js:

go: function(id){
    window.location.href = baseUrl+'/id/'+id;
}
    
asked by davidplpz 20.01.2017 в 17:05
source

2 answers

0

Is there a possibility that you can execute the following order on your Javascript?

document.getElementById('enlace').setAttribute('href', baseUrl+'/id/'+id);

Where your link would be as follows:

<a rel="nofollow" id="enlace" href="#" class="automatic">Enlace</a>

This will assign the href attribute without having to click on the link, so that the href is assigned.

    
answered by 20.01.2017 / 17:29
source
0

The html code would be this

<a rel="nofollow"  oncontextmenu="link.Generator.go2('<?echo$pageId?>')" onclick="link.Generator.go('<?echo$pageId?>')"   class="automatic"></a>

And these would be the functions:

go: function(id){
    window.open(baseUrl+'/id/'+id);
}

go2: function(id){
    window.locationf=baseUrl+'/id/'+id;
}

oncontextmenu what it does is call the function when it detects the right click event.

    
answered by 20.01.2017 в 17:14