Roald Andre Kvarv
Roald Andre Kvarv

Reputation: 197

Shorten long code lines containing anchor tags in HTML

I want a max character length of 80 characters on my text. It is being stopped by long, long links to which I can not find a way to shorten down in the actual code. Not on the website, but the actual code. Just to make it look cleaner and shorter and without the use of websites like shorturl.

An example of a long link that i have is this.

<a href="https://www.ukrinform.net/rubric-polytics/3308431-usukraine-strategic-partnership-commission-to-meet-this-fall.html">

But i want to be able to like cut it in half in the code so it displays for example like this:

<a href="https://www.ukrinform.net/rubric-polytics
/3308431-usukraine-strategic-partnership-commission-to-meet-this-fall.html">

All I am getting is errors with it taking on the first part of the link that contains the line break. I can not find any way to fix the problem.

I wonder if there is any possible way I can get done something similar.

Upvotes: 2

Views: 341

Answers (1)

topsoftwarepro
topsoftwarepro

Reputation: 822

Option 1

You can use something like a url shortener, and then past the shortened link in your code.

URL shorteners

Option 2

You can create another webpage with a list of the links and and use a GET request to access them.

If you are using PHP:

<script>
    const links = [
                   "https://long-link-1.com",
                   "https://long-link-2.com",
                   "https://long-link-3.com"
                  ]
    window.location.replace(links[<?php echo $_GET["linkID"]; ?>-1])
</script>

display web page (Example):

<a href="/longlinks.php?linkID=1"></a>

Upvotes: 1

Related Questions