linuxgx
linuxgx

Reputation: 389

Need to replace a URL on page using JS

I need some way to replace

https://stusys.harpercollege.edu/class-schedule/class-schedule.html?course=0008&subject=LAG&term=202095

with

https://stusys.harpercollege.edu/class-schedule/class-schedule.html?course=0008&subject=LAG&term=202090

using JS. The page is generated dynamically and now we need some one-off half-semester classes added.

Does anyone know how to swap these URLs with something I can just toss into the footer.

Upvotes: 0

Views: 61

Answers (3)

kmoser
kmoser

Reputation: 9273

It sounds like you want a script you can drop in to your page which will dynamically change some of the hyperlinks. Since your page is already loading jQuery, this should do the trick:

<script>
    $('a[href="https://stusys.harpercollege.edu/class-schedule/class-schedule.html?course=0008&subject=LAG&term=202095"]').each(function(){
        $(this).attr('href', 'https://stusys.harpercollege.edu/class-schedule/class-schedule.html?course=0008&subject=LAG&term=202090' )
    })
</script>

Upvotes: 0

Lawrence Cherone
Lawrence Cherone

Reputation: 46602

Use URL():

var url = new URL('https://stusys.harpercollege.edu/class-schedule/class-schedule.html?course=0008&subject=LAG&term=202095')
url.searchParams.set('term', 100)
console.log(url)

Upvotes: 1

robinpe
robinpe

Reputation: 1

I dont know if I fully understand your question, but if you just are going to replace the two URLs you can use the Javascript replace method.

Upvotes: 0

Related Questions