mameesh
mameesh

Reputation: 3761

How do I create an html link that has a link name, the same as the URL address?

Is this the easiest way in an html doc to create a link to a page that has the same name as the url?

So basically it will say:

Please click the following link:
http://test.com.

That is all I want it to say.

The code I wrote for this is as follows:

<A href="http://test.com">http://test.com.</A>

Or is there a more all inclusive way where you don't have to write the name of the url twice?

Obviously my code doesnt include the initial text, this is just for example purposes.

Upvotes: 1

Views: 1644

Answers (3)

Nathan
Nathan

Reputation: 7032

Unless you want to copy the URL from one place to another using JavaScript, you will have to write the URL twice.

I advise agains the JavaScript copying, because its performance and SEO costs are much worse than the cost of typing everything twice.

Upvotes: 1

Chris Fletcher
Chris Fletcher

Reputation: 2387

Why don't we just sidestep the issue by making our links more semantically-rich?

Instead of:

For more information on our delicious pizza, visit <a href="http://www.pizzasrawesome.com">www.pizzasrawesome.com</a>.

Use this:

Read more about our <a href="http://www.pizzasrawesome.com">delicious pizza</a>.

Upvotes: 1

Abhi Beckert
Abhi Beckert

Reputation: 33369

What you have got now is the easiest way.

If it's not an option for some reason you can use server side scripting to search the page content for URLs and wrap an <a> tag around them.

This will require some very complicated regex. Daring Fireball has a very good blog post instructing you how to do this, and explaining exactly why it's actually impossible for this to be perfectly reliable (which is probably why HTML doesn't allow it):

http://daringfireball.net/2010/07/improved_regex_for_matching_urls

I've done this sort of thing before (with emails actually) and it's very difficult and took years to get right. If at all possible, you should just do what you're already doing - manually type in the <a> tag yourself.

Alternatively, you could use something like smarty (for PHP. I don't know what the ASP equivalent would be) to write something along the lines of the following, to programatically generate the full <a> tag:

{link url='http://example.com'}

Upvotes: 1

Related Questions