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

82
Views
JS Function from URL

please help me. I have a code inside any of my posts.

post link is

link1    https://mysite.ext/mypost.html
link2    https://mysite.ext/mypost.html?id0987

    <script>
 let newuserid = window.location.search;
 if (newuserid = id0987) {
    aleret('Welcome, You reached throught ref id 0987');
 }
 </script>

I'm new to Code Life and I just create something like this. If someone comes up with 'link2' then run this function otherwise do nothing. The definition code is just one example.

Explain that if the URL of a post is post-url? Idxxxx. Then run the function xxxx. If the post url? Idyyyy Then run the function yyyy. The js code functions are already written in the current post. I know we can't create a function from a URL but a pre-written script can be run if the URL is like this do this. And in the URL we will track a referral ID.

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Give this a try

<script>
let urlID = window.location.href.indexOf('id0987');
if (urlID != '-1'){
alert('Welcome, You reached throught ref id 0987');
}
</script>
about 4 years ago · Juan Pablo Isaza Report

0

You should put quotes here newuserid == "id0987"!
I have also put .substr(1) at the end. It removes ? from the url.

window.location.search => "?id0987"
window.location.search.substr(1) >=> "id0987"

<script>
let newuserid = window.location.search.substr(1);
if (newuserid == "id0987") { //Here!!
   window.alert('Welcome, You reached throught ref id 0987');
}
</script>
about 4 years ago · Juan Pablo Isaza Report

0

you're using the 'if' statement. when you compare whether a value is equal, you need to use == and not =.

therefore:

 let newuserid = window.location.search;
 if (newuserid == 'id0987') {
    alert('Welcome, You reached throught ref id 0987');
 }
 </script>

would probably make your code work. notice i also wrapped id0987 with '' and changed aleret to alert.

another tip - in javascript you usually perform equals assertion using === - the triple equate operator makes sure that the type of the value is also the same.

but that's for a different question.

about 4 years ago · Juan Pablo Isaza Report
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!