|
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!
Categorized:
CGI Scripts and Web Site Programming
(Article 7714,
Written by Dave Taylor)
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!
Rather amazingly, there are no comments on this article yet.
I have something to say, now that you mention it, but ...
I do have a comment, now that you mention it!
|
Recommended
Recent Entries
Search
I Need Help!
Apple iPad Help
Articles and Reviews Auctions and Online Shopping Blogs and RSS Feeds Building Web Site Traffic Business and Management CGI Scripts and Web Site Programming Computer and Internet Basics d) None of the Above Facebook Help Google Plus Help HTML and CSS Industry News and Trade Shows iPhone and Cell Phone Help iPod, Sony PSP and MP3 Player Help Mac OS X Help Pay Per Click (PPC) Advertising Search Engine Optimization (SEO) Shell Script Programming Tech Support Video Help The Writing Business Twitter, LinkedIn and Social Network Help Unix and Linux Help Video Game Tips and Help Windows PC Help WordPress Help |