سؤال

I am clutching at straws a little bit here, I want to do as the title says, when the page loads I would really love some javascript to fire off some code that checks the url, and reads the end of it. I then want to have an 'if' that says (URL ends with =en?check this radio:do nothing). the code I have attempting at fitting already is messy at best but I will show you to help you understand my lack of ability and to better explain my query:

window.onload = function(){

    var url = window.location.href;
    var lastPart = url.substr(url.lastIndexOf('/') + 1);

    if (lastPart === "=en") {
        radiobtn = document.getElementById("123456789");
        radiobtn.checked = true;
    }
};

Thank you guys!

هل كانت مفيدة؟

المحلول

This was a serious lack of understanding of the code of the code I was attempting to use.

var lastPart = url.substr(url.lastIndexOf('/') + 1);

I didnt realise that this was reading everything after the char '/'. After changing it to '=' it worked perfectly!

Sorry community!

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top