Answer: Use the window. location. href Property location. href property to get the entire URL of the current page which includes host name, query string, fragment identifier, etc.
open() function contains the URL string of a webpage, which you want to open. If you do not specify any URL in this function, it will open a new blank window (about:blank). Passed URL will load into a new tab/window. URL will load into the parent window or frame that is already opened.
Open in specific window. Chrome will by default open any link in the same window as it was clicked. If you have multiple chrome windows open, this extension will add a right-click menu allowing you to choose which window to open the link in.
You wanted to access the root document of server www.google.com
, which is done using the url https://www.google.com/
. You provided a relative url for document www.google.com
instead.
Keep in mind that window.open
accepts both relative and absolute urls, so it can't assume you left out https://
as it does when you use www.google.com
in the address bar.
Maybe an example will help. Say the current page is http://www.example.com/dir/foo.html
.
window.open("popup.html", "_blank")
openshttp://www.example.com/dir/popup.html
.window.open("www.google.com", "_blank")
therefore openshttp://www.example.com/dir/www.google.com
.The browser has no way of knowing you actually wanted https://www.google.com/
when you said you wanted http://www.example.com/dir/www.google.com
since the latter could be valid.
You have to prepend http://
in your url:
$(document).ready(function () {
$('#mybtn').on('click', function () {
window.open("http://www.google.com", '_blank');
});
});
Fix: http://jsfiddle.net/FUYTY/4/
Try adding http:// beforehand (see Fiddle http://jsfiddle.net/lkritchey/FUYTY/3/)
$( document ).ready(function() {
$('#mybtn').on('click', function() {
window.open("http://www.google.com", '_blank');
});
});
Some more information: If you include a '/' beforehand, it appends your string to the root URL. If you just list the string, it appends it to the current full URL. If you include either http:// or https:// it knows to use only what you put in your string (i.e. http://www.google.com)
Preface your urls with http://
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With