Skip to content
Advertisement

remove last directory in URL

I am trying to remove the last directory part of an URL. My URL looks like this: https://my_ip_address:port/site.php?path=/path/to/my/folder. When clicking on a button, I want to change this to https://my_ip_address:port/site.php?path=/path/to/my. (Remove the last part). I already tried window.location.replace(//[A-Za-z0-9%]+$/, “”), which results in https://my_ip_address:port/undefined. What Regex should I use to do this? Answer Explanation: Explode by “/”, remove the last element

HTML form dropdown menu specify number range

I want to specify number range in drop-down menu list like 1-24 from example i am currently doing following is there any way we can say use 1-24 and it dynamically create drop-down menu, I guess we need to use Javascript but i don’t know how to code them? Answer You don’t need Javascript, you can use a PHP for

Hold button -> repeat function

I’m trying to achieve something which souldn’t be hard to do, but everything I’ve tried so far hasn’t worked. I have a function that changes a value every time I click a button, and what I want is: when I hold this button, the value should keep changing. This is what I’ve tried and hasn’t worked, setInterval and setTimeout won’t

Get element’s xpath in javascript

I am developing in javascript and I would need to get the xpath of the element clicked. I know that in order to get the id we can do : How could I do to get the xpath ? Regards. Answer There are many ways to access an element with XPath. For example you can access it by node name

Use of window.location doesn’t work on iPad

I’m using some JavaScript that will redirect the user to another URL after a fixed period of time. This is working well on all browsers but on an iPad 3 I have to test on it isn’t working. The timeout fires and I call and I’ve also tried I can see the URL in the browser changing to www.someurl.ocom but

requestAnimationFrame Refresh Rate

I’m using requestAnimationFrame to draw players in my game. One of the players is moving faster than everybody else. I did some checking with him and he told me that his monitor has a 120hz refresh rate. I’m assuming this means has can process frames faster than others resulting in faster movement speed. Any ideas as to how I can

Sort array on key value

I have a function which sorts by name currently and an array of value / key pairs. I wonder how can I pass the key on which sort is being performed so I can call the same function every time like so: Answer [edit 2020/08/14] This was rather an old answer and not very good as well, so simplified and

Advertisement