Free Republic
Browse · Search
News/Activism
Topics · Post Article

To: cynwoody

Would you be so kind to repeat how to fix a text filled with relative hyperlinks so that they are converted to absolute hyperlinks?

I should have saved it then. I’ll try to save it now.


25 posted on 04/22/2011 12:10:33 AM PDT by neverdem (Xin loi minh oi)
[ Post Reply | Private Reply | To 13 | View Replies ]


To: neverdem
Would you be so kind to repeat how to fix a text filled with relative hyperlinks so that they are converted to absolute hyperlinks?

I should have saved it then. I’ll try to save it now.

You need to go though the page, find all the relative URLs, and change them to absolute URLs by prepending to each the host name of site which hosts the page you are working with.

The problem arises when you attempt to post on FR HTML code excerpted from a page hosted somewhere else. E.g., if you go to the Google homepage, there is a link towards the bottom entitled About Google. If you inspect the source code for the page (in Firefox, select the link text and the select View Selection Source), you will see:

<a href="/intl/en/about.html">About Google</a>

That won't work if you copy and paste it as is into a post on FR. However, if you first run the following script against the Google homepage, the link will be made absolute and suitable for use on any site:

javascript:
var links = document.links;
for (var x = 0; x < links.length; ++x) links[x].href = links[x].href;
var pix = document.images;
for (var x = 0; x < pix.length; ++x) pix[x].src = pix[x].src;
void 0;

What that does is, run through the links and images on the current page and change the link associated with each to absolute (if it wasn't already absolute). At first glance, assigning something to itself would appear not to do anything. However, when you retrieve the URL from a link or image object, the object provides you with the absolute version, even if it's keeping a relative URL internally. So, the end result of the above is to assign the absolute version of the URL to each link and image.

Now, the obvious question is, how do you conveniently run that code on a page you are about to excerpt? The answer is to house the code in a bookmarklet. I'd put one here, except FR filters out JavaScript. However, there is an Absolutify bookmarklet on this page. To install it, drag the Absolutify link to your Bookmarks Toolbar. Then, when on a page you want to excerpt, click your Absolutify link before using View Selection Source or similar. If you do that on the Google homepage and then select the source for the About Google link, it should now read:

<a href="http://www.google.com/intl/en/about.html">About Google</a>

That link should work from any site.


Of course, there are other challenges in transferring HTML. They mainly have to with the heavy use of style sheets to define a page's appearance. The basic HTML tags work on FR, but FR filters out CSS even if you manage to copy it. So, you may have to approximate the original page's appearance by inserting some basic tags. E.g., a page might contain something like this:

<div class="sectionHeading">Early Life</div>

The identifier sectionHeading refers to a style sheet specification somewhere that details exactly what font face, size, weight and color to use for section headings. To put that in a post on FR, you'd have to settle for an approximation of the original appearance, for instance using an H3 tag or similar.

64 posted on 04/22/2011 11:53:13 AM PDT by cynwoody
[ Post Reply | Private Reply | To 25 | View Replies ]

Free Republic
Browse · Search
News/Activism
Topics · Post Article


FreeRepublic, LLC, PO BOX 9771, FRESNO, CA 93794
FreeRepublic.com is powered by software copyright 2000-2008 John Robinson