-
Tell me if I am wrong..
I want to write a JavaScript, I am thinking JavaScript so I can call it from a JS Library any time I need to. I want the Script to check all URL addresses pulled from the DB and displayed to the web page making sure they have http:// in front of the rest of the URL. If http:// already exists then ignore. But I want to guarantee the links are clickable. I think I will not have them open in a new window for now. Giving the visitor the freedom to exercise the use of the "back" button.
Does this sound like a job for JavaScript or would VBScript be better?
-
HTTP stripping and checking URLs
Hi there!
>Does this sound like a job for JavaScript or would
>VBScript be better?
If you have to use JavaScript or VBScript for some reason just ignore this posting.
Otherwise:
Ruby (an OO script language) is great at string handling and web things apart from being a great language in itself.
You didn't give much info on what you mean with the DB. Pulled out, into a text file, or what?
The script takes an address, fixes http:// and gets the root page and tells you whether it was successful or not.
I've left out all details concerning generating the actual HTML code. That's the easy part :-) You can use Ruby to access databases.
If you want to check out Ruby, go to http://www.rubycentral.com/ for a Windows version or http://www.ruby-lang.org for a Linux version.
Store the code below in urlcheck.rb
Start a command prompt
Type: ruby urlcheck.rb
I know ruby can be installed on web servers but I've never done it myself.
Feel free to ask me any questions if you choose to try this out.
(my nice indentation will be lost, stupid system)
/rob
require 'net/http'
a = [
"http://sysopt.earthweb.com",
"www.nasa.gov",
"www.notworking.com"
]
a.each do |url|
# Remove http:// from all addresses to make them consistent
# Net::HTTP.new also wants the address without http://
# The regular expression looks pretty weird because / has
# to be escaped
urlWithNoHTTP = url.sub( /http:\/\//, '' )
print "http://#{urlWithNoHTTP}"
# Try to get the root page (/) and catch any errors
begin
h = Net::HTTP.new(urlWithNoHTTP, 80)
resp, data = h.get('/', nil )
rescue StandardError => bang
puts " (error = #{bang})"
else
puts " (ok)"
end
end
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
New Security Features Planned for Firefox 4
Another Laptop Theft Exposes 21K Patients' Data
Oracle Hits to Road to Pitch Data Center Plans
Microsoft Preps Array of Windows Patches
Microsoft Nears IE9 Beta With Final Preview
Simplified Analytics Improve CRM, BI Tools
Android Passes RIM as Top Mobile OS in 2Q
VMware Updates Hyperic System Management
File Monitoring Key to Enterprise Security
LinkedIn Snaps Up SaaS Player mSpoke
|
Bookmarks