Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

223
Views
Get the domain and page name from a String URL

Well i'm currently have some issue about manipulating an URL.

Technically what i want is to get the domain name and the page name from a page.

For example :

www.myWebSite.com => domain : myWebSite
http://myWebSite.com => domain : myWebSite
myWebSite.com/xxx.hmtl => domain : myWebSite page : xxx
over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

window.location.hostname; //Domain name

$("title").text(); //Page name

EDIT:

var loc = window.location;

var filename = loc.pathname.split("/");
filename = filename[pathname.length-1];

alert("Domain: "+loc.hostname);
alert("Filename: "+filename);
over 4 years ago · Santiago Trujillo Report

0

try with url.match(/:\/\/(.[^/]+)/)[1]

example :

var r = /:\/\/(.[^/]+)/;
"http://stackoverflow.com/questions/5343288/get-the-domain-and-page-name-from-a-string-url".match(r)[1] 
=> stackoverflow.com
over 4 years ago · Santiago Trujillo Report

0

Use window.location.hostname or window.location.host. Check location reference.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!