Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getting index.html from href

Status
Not open for further replies.

801119

Programmer
Apr 10, 2000
311
0
0
SE
Greetings all...

Just wondering, how do I strip down to everything after .com?
is there a easy way.. or must I create my own script? (that I can, just to laizy to do it right now) :)

thanks for anyhelp... My codes look like something a kid wrote
I have absolutely no idea what I am talking about
Somehow I still manage to make it work
 
hi

i remember some sort of your question,

take a look at thread216-196304

i don't know an easy way.. Victor
 
Use a regular expression and extract everything after the last slash.
 
doublehelix...

sicne I'm not used with those expressions I wouldn't know how to make one! (my solution had been a loop *haha*).. could you give me a hint were to start?

and vituz, the thread you pointed towards didn't do what I wanted, it.. (have no idea what it does) but I would guess it checked for the existance of My codes look like something a kid wrote
I have absolutely no idea what I am talking about
Somehow I still manage to make it work
 
nope, there i used *those expressions* to split the url entered apart to
~domain (hostname, before first / symbol, e.g. www.tek-tips.com)
~pathname (here it would be just /)
~filename (viewthread.cfmblabla)

Code:
var _pat1=/([^\/]*)(\/.*)*/
var parts={
_hostname : url.match(_pat1)[1],
_pathname : url.match(_pat1)[2],
_patharr  : url.match(_pat1)[2].split("/"),
_file     : ""
}
var _temp=parts._patharr
parts._file=_temp[_temp.length-1]
_temp.length--;
parts._pathname=(_temp.length==1) ? "/" : _temp.join("/")

//alert("there are\nhostname: "+parts._hostname+"\npathname: "+parts._pathname+"\nfile: "+parts._file)

some explanations:

var _pat1=/([^\/]*)(\/.*)*/ - a pattern, first brackets matches everything before first /, second - everything else..

url.match(_pat1) - this catches matches of entered url with given pattern, if assigned to a variable (like in my case) it returns an array of matches (the length of array equals to the amount of bracket-qroups [2 in this case] & numbering starts from 1, but not from 0)
so,
url.match(_pat1)[1] would catch the first match (meaning hostname) & second - (blabla[2]) - the second match (pathname)

then i split that pathname by "/" & the last value in resulting array is a filename; i qrab it outta here & join the rest to the "_pathname" variable

blabla (tired explaining)

and so on..

what can i say? i guess it is too complicated.. but i like to write things that might be used in many ways :) Victor
 
Try this too...


<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>
<html>
<head>
<title>File name Capture from a URL</title>
</head>

<body>
<script language=&quot;JavaScript&quot;>
<!-- Instantiate Regular expression Object -->
var myRegExp=new RegExp();
var myRegExp = /(\/)+/;

<!-- Get URL and convert to String Object -->
var url_temp=window.location;
url_temp=String(url_temp);

<!-- Split URL on / -->
var url_array=url_temp.split(myRegExp);

<!-- Display Elements of URL -->
document.write(&quot;domain: &quot;+url_array[1]+&quot;<br>&quot;);
document.write(&quot;path: &quot;);
for(i=2;i<url_array.length-1;i++)
{
document.write(url_array+&quot;/&quot;);
}
document.write(&quot;<br>&quot;);
document.write(&quot;file: &quot;+url_array[url_array.length-1]);

</script>
</body>
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top