| | |
What do you use to parse the url?
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Mar 2005
Posts: 2
Reputation:
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
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.
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
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:
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; }
![]() |
Similar Threads
- 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
| Thread Tools | Search this Thread |
acid2 ajax ajaxcode ajaxexample ajaxjspservlets automatically beta box browser bug captchaformproblem checkbox close codes createrange() css cursor debugger decimal dependent disablefirebug dom download dropdown editor element engine enter error events explorer ext file firefox form forms frameworks getselection google gwt gxt hiddenvalue highlightedword hint html htmlform ie7 ie8 iframe index internet java javascript javascripthelp2020 jquery jsf jsfile jsp jump listbox maps masterpage math media menu microsoft mp4 object onmouseoutdivproblem onreadystatechange paypal pdf php player position problem programming progressbar prototype redirect regex runtime safari scale scriptlets search security select size software sql text textarea unicode w3c window windowofwords windowsxp wysiwyg \n






