I need to be able to grab part of a dynamic url in order to display an image (and a corresponding website address).
The url in the browser can be like:
The syntax is always the same - starting with /vacancy/application/32-numbers/6-numbers/ and then the part I'm interested in. The ?iso=gb code is not always there.
How do I grab the numbers in bold?
I have tried this:
combined with this bit to display the result:
var dep = window.location.href.slice(window.location.href.indexOf('?iso') - 5).split(',');
if (dep == "64073?iso=gb")
var banner = '/files/LB.jpg'
var url = 'http://www.website1.com'
else if (dep == "64074?iso=gb")
var banner = '/files/LT.jpg'
var url = 'http://www.website2.com'
var banner = '/files/LK.jpg'
var url = 'http://www.website3.com'
And it actually works - but only if the url ends with ?iso=gb - and this is not always the case.
document.write('<a href='+url+' target=\"_blank\"><img src='+banner+' /></a>');
So, does anybody have an idea how to solve this? Or is there a smarter way to do this?