Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

macbaseball

macrumors 6502a
Original poster
Feb 27, 2005
987
0
Northern California
I'm trying to figure out how to generate a URL which then would be a link.

What I want to do is only change the middle part of a URL. Most of the codes I'm seen only can change the end of the URL. Could someone help me out.
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
Basically you are on your own. If you are using the window.location object you can get the various parts of the URL:

If your document is at http://myhost.com:8080/my/folder/path/document.html?search=test#fred

hash: returns #fred
host: returns myhost.com:8080
hostname : returns myhost.com
href: the entire text
pathname: returns /my/folder/parh/document.html
port: returns 8080
protocol: returns http:
search: returns ?search=test

Notet that these are read/write so you can do (say) window.location.path = '/my/new/path/page.html';

If you just have a string then it's up to you to parse it.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.