Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

111
Views
Compare URL with string and path and insert link text

It is a post template that should work for different posts and in different languages. There should be no different templates for different languages. That's why I thought of the following. I compare the loaded url with string and path. If the condition is met, a URL and text will be added to the following link. Since I'm still at the beginning, I'm interested in your feedback and other approaches. Maybe you have any comments. So I can see what I can do better. Please help me so I can learn more. Thank you

var url = window.location.href
var path = window.location.pathname
var output1 = "http://localhost";
var output2 = output1 + path;

$(window).on('load', function () {
  if (url == output1 + path) {
    $("a.blog-wort").attr("href", "http://localhost/landing1/");
    $('a.blog-wort').text('text 1');
  } else if (url == output2) {
    $("a.blog-wort").attr("href", "http://localhost/en/landing2/");
    $('a.blog-wort').text('text 2');
  } else if (url == output2) {
    $("a.blog-wort").attr("href", "");
    $('a.blog-wort').text('text 3');
  }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<a class="blog-wort"></a>

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!