Reputation: 1683
Code
<a href="www.someurl.com" id="equipment_url_readonly">www.someurl.com</a>
$(document).on('click','#equipment_url_readonly', function(event) {
event.preventDefault();
var url = $(this).attr('href');
console.log(url); //It console logs correctly the url
window.open(url,"_blank");
});
But whenever I click on the anchor tag, it prepends the url of the parent,
so for example my current page that has that url is www.mycurrentpage.com/this-page
. When I click on that link, it opens a new window with a url of:
www.mycurrentpage.com/this-page/www.someurl.com
Any idea how this happened?
Upvotes: 2
Views: 4049
Reputation: 15490
try the below, i think its enough for your purpose. hope it will helps.
you have to use http://
or //
before your url
<a href="javascript:void(0);" onclick="window.open('http://www.someurl.com', '_blank');" >www.someurl.com</a>
Upvotes: 0
Reputation: 173572
As mentioned in the comments, the problem is that your anchor doesn't contain an absolute URL because it misses the protocol (i.e. "http://" or even "//").
This should fix it:
<a href="//www.someurl.com" id="equipment_url_readonly">www.someurl.com</a>
The above will work for both secure and non-secure pages.
Upvotes: 3
Reputation: 18217
You can accomplish opening a new window without any Javascript.
<a href="http://www.someurl.com" target=_blank>www.someurl.com</a>
Upvotes: 1