/    Sign up×
Community /Pin to ProfileBookmark

Read url using JavaScript

Hi folks,

given a url such as mydomain.com/folder/page1/

is it possible using JS to get on a variable the value “page1” ?

Thanks for help.

Max.

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@FangOct 15.2008 — Only if it is in your domain.
Copy linkTweet thisAlerts:
@mpace030authorOct 15.2008 — Yes, it's my own domain, do you have some tip?

Max.
Copy linkTweet thisAlerts:
@FangOct 15.2008 — Load the document into an iframe and reference it from the parent document.
Copy linkTweet thisAlerts:
@vgorbachOct 15.2008 — Assuming that you need to get last element from your URL following example will do the job:

[I]<SCRIPT language="JavaScript">

<!--

var str = "mydomain.com/folder/page1/";

var arr = str.split( new RegExp( "[/]{1}", "g" ) );

alert(arr[arr.length-1]);

//-->

</SCRIPT>[/I]
Copy linkTweet thisAlerts:
@rnd_meOct 15.2008 — are you wanting to load the file into a string?

for that, simply use an xmlHttpRequest.

you should be able to pass it the whole pathname without parsing.
×

Success!

Help @mpace030 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.8,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...