-1

Currently I have this bookmarklet:

javascript:currentUrl=document.location.href;document.location.assign(currentUrl+'embed');

What this does is that it grabs the current URL www.example.com/knZg_INW8fL/ and adds embed behind it so it can be embeded

However, sometimes, the URL will have a ?hl=en behind it. How can I remove that and simultaneously add embed behind it?

wolnavi
  • 183
  • 1
  • 14

1 Answers1

1

the random chars will not have ? because it is a special character. the easiest way is to split the string on ? and take the first part!

If you also want to remove the last '/' from the string, you can slice it off

javascript:document.location.assign(document.location.href.split('?')[0].slice(0,-1));

console.log('www.example.com/knZg_INW8fL/?hl=en'.split('?')[0].slice(0,-1));
Dhananjai Pai
  • 5,914
  • 1
  • 10
  • 25
  • 1
    Thank you, this is what I am looking for... And so sorry for the confusing question earlier on. Thumbs up to you for understanding my question even though it was so confusing – wolnavi Oct 08 '19 at 20:53