
How do I create a custom bookmark that grabs the current URL?I've seen a number of different sites where you can drag a link onto your bookmark bar in a browser and then have that bookmark act as a tiny little program that grabs and sends specific information. I want one like that for a bookmark program of my own, where I have a CGI backend and want to be able to visit a page, click on my link, and have the URL of that page handed to my script. Does that make sense? Your question is a bit confusing, yes, but I know what you mean because a few months ago I wrote a similar sort of utility that let me disseminate my favorite sites into an archive system I wrote on my server (yeah, kinda geeky, but, in the immortal words of Popeye, I yam what I yam. :-) Anyway, here's the Javascript code I wrote for the bookmark itself: javascript:location.href='http://www.mydomain.com/mybookmarkutility.cgi?u='+encodeURIComponent(location.href)+'&t='+encodeURIComponent(document.title);
As you can see, it's all a little Javascript trick here, where I'm accessing various elements of the document object model (the "DOM" for insiders), in this case the URL of the current page (that's location.href) and the title of the page too (that's document.title). You can't just slap those onto a new URL, however, so we also use a handy Javascript element called encodeURIComponent to turn spaces into "+", mask control characters and punctuation, etc. If I was on a page with the URL, say, of "http://www.mypage.com/" and a title of "Interesting Information", then the resultant call to my CGI script would be: ?u=http://www.mypage.com/&t=Interesting+Information
The CGI script then simply needs to unwrap and identify the "u" and "t" variables to extract the URL and title again within the script. This should be easy to accomplish depending on your CGI programming skills. For your purposes, you probably don't need the title of the page, so your task would be even easier: just delete the "t=" title portion. In terms of how to get a bookmark set for your complicated Javascript code, the bst solution is to do something like this: <a href="add javascript code here">Drag this bookmark onto your toolbar</a>
Which would be implemented thusly: Drag this bookmark onto your toolbar (or, if you prefer, right-click and choose "Bookmark this link" or similar) That should get you going with your project. Good luck!
Help others find this article at Del.icio.us, Digg, Netscape, Reddit, and Stumble Upon
Categorized:
CGI Scripts and Web Site Programming
(Article 7714)
Tagged: cgi programming, javascript Previous: Four months of the Apple iPhone: Thoughts... Next: How can you tell if a Limewire file is legal or illegal? Subscribe!
Never miss another useful Q&A article again! Subscribe to AskDaveTaylor with Google Reader.
Rather amazingly, there are no comments on this article yet.
I have a lot to say, but ...
I do have a comment, now that you mention it!
|
![]()
Search
Find just the answers you seek from among our 2300+ free tech support articles by using our Lijit search engine.
Help!
Subscribe to
Ask Dave Taylor!
Free Updates!
Sign up and get free weekly updates and special offers on books, seminars, workshops and more.
Articles and Reviews
Auctions and Online Shopping Blogs and RSS Feeds Building Web site traffic Business and Management Cell Phones and Mobile Phones CGI Scripts and Web Site Programming Computer and Internet Basics d) None of the Above HTML and CSS Industry News and Trade Shows Mac OS X Help MySpace, Facebook, Twitter and Social Network Help Pay Per Click (PPC) Search Engine Optimization Shell Script Programming Sony PSP, MP3 Players, Etc. The Writing Business Unix and Linux Help Video Game Tips and Help Windows Help
Recent Entries
Book Links
|