•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 375,174 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,214 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 9269 | Replies: 3
![]() |
•
•
Join Date: Mar 2005
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
I wouldn't even consider myself a rookie with javascript but know it can be done, so thanks for any help.
What function would I use to have javascript read the page it is on, grab the url which is like:
http://site.com/boards/index.php?sho...37&mode=linear
and say if the url includes "mode=linear" then apply this style sheet?
Thanks!
Will
What function would I use to have javascript read the page it is on, grab the url which is like:
http://site.com/boards/index.php?sho...37&mode=linear
and say if the url includes "mode=linear" then apply this style sheet?
Thanks!
Will
•
•
Join Date: Dec 2004
Location: Lincoln Park, Michigan
Posts: 1,744
Reputation:
Rep Power: 7
Solved Threads: 107
I suppose you could do a
and then do a substr or substring on the url, and see if it's in there. There might be an easier way, but that's probably how I'd do it.
somevariable = window.location;
and then do a substr or substring on the url, and see if it's in there. There might be an easier way, but that's probably how I'd do it.
•
•
Join Date: May 2007
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
Well, try this function, it should be working.
javascript Syntax (Toggle Plain Text)
function parseURL(buffer) { var result = { }; result.protocol = ""; result.user = ""; result.password = ""; result.host = ""; result.port = ""; result.path = ""; result.query = ""; var section = "PROTOCOL"; var start = 0; var wasSlash = false; while(start < buffer.length) { if(section == "PROTOCOL") { if(buffer.charAt(start) == ':') { section = "AFTER_PROTOCOL"; start++; } else if(buffer.charAt(start) == '/' && result.protocol.length() == 0) { section = PATH; } else { result.protocol += buffer.charAt(start++); } } else if(section == "AFTER_PROTOCOL") { if(buffer.charAt(start) == '/') { if(!wasSlash) { wasSlash = true; } else { wasSlash = false; section = "USER"; } start ++; } else { throw new ParseException("Protocol shell be separated with 2 slashes"); } } else if(section == "USER") { if(buffer.charAt(start) == '/') { result.host = result.user; result.user = ""; section = "PATH"; } else if(buffer.charAt(start) == '?') { result.host = result.user; result.user = ""; section = "QUERY"; start++; } else if(buffer.charAt(start) == ':') { section = "PASSWORD"; start++; } else if(buffer.charAt(start) == '@') { section = "HOST"; start++; } else { result.user += buffer.charAt(start++); } } else if(section == "PASSWORD") { if(buffer.charAt(start) == '/') { result.host = result.user; result.port = result.password; result.user = ""; result.password = ""; section = "PATH"; } else if(buffer.charAt(start) == '?') { result.host = result.user; result.port = result.password; result.user = ""; result.password = ""; section = "QUERY"; start ++; } else if(buffer.charAt(start) == '@') { section = "HOST"; start++; } else { result.password += buffer.charAt(start++); } } else if(section == "HOST") { if(buffer.charAt(start) == '/') { section = "PATH"; } else if(buffer.charAt(start) == ':') { section = "PORT"; start++; } else if(buffer.charAt(start) == '?') { section = "QUERY"; start++; } else { result.host += buffer.charAt(start++); } } else if(section == "PORT") { if(buffer.charAt(start) = '/') { section = "PATH"; } else if(buffer.charAt(start) == '?') { section = "QUERY"; start++; } else { result.port += buffer.charAt(start++); } } else if(section == "PATH") { if(buffer.charAt(start) == '?') { section = "QUERY"; start ++; } else { result.path += buffer.charAt(start++); } } else if(section == "QUERY") { result.query += buffer.charAt(start++); } } if(section == "PROTOCOL") { result.host = result.protocol; result.protocol = "http"; } else if(section == "AFTER_PROTOCOL") { throw new ParseException("Invalid url"); } else if(section == "USER") { result.host = result.user; result.user = ""; } else if(section == "PASSWORD") { result.host = result.user; result.port = result.password; result.user = ""; result.password = ""; } return result; } function ParseException(description) { this.description = description; }
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb JavaScript / DHTML / AJAX Marketplace
- Help. Parse error in PHP code (PHP)
- Cross Link Id Problem (Perl)
- Xul (RSS, Web Services and SOAP)
- Regarding previous programming q 2 (C)
- parsing html (Java)
- how to find stock information with php script (PHP)
- I need help with a parse error! (PHP)
- Google Trends (Search Engine Optimization)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Where to get good JavaScript Tutorials?
- Next Thread: "add this site to your bookmarks" in firefox



Linear Mode