Thursday, 15 April 2010

javascript - Why is window.open prepending a default url? -



javascript - Why is window.open prepending a default url? -

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 url window.open(url,"_blank"); });

but whenever click on anchor tag, prepends url of parent, illustration current page has url www.mycurrentpage.com/this-page. when click on link, opens new window url of:

www.mycurrentpage.com/this-page/www.someurl.com

any thought how happened?

as mentioned in comments, problem anchor doesn't contain absolute url because misses protocol (i.e. "http://" or "//").

this should prepare it:

<a href="//www.someurl.com" id="equipment_url_readonly">www.someurl.com</a>

the above work both secure , non-secure pages.

javascript jquery html

No comments:

Post a Comment