My url on a page is like:
http://www.example.com/dir1/file.html?a=1
I need to extract:
http://www.example.com
how can I do this in javascript?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The
window.locationis an object with useful properties for this, details in this JSBin.For that JSBin URL (http://jsbin.com/etima), here’s what you see (with some irrelevancies removed):
href: http://jsbin.com/etimaprotocol: http:hostname: jsbin.comhost: jsbin.comport:pathname: /etimasearch:hash:So basically, combine the
protocol, thehostname, and theportif any: