Why javascript code can’t execute command ?. The console tab still doesn’t see the command I entered [closed]

Html is normal, but Javascript code can’t execute command into html.
Html is normal, but Javascript code can’t execute command into html.
Html is normal, but Javascript code can’t execute command into html.
Html is normal, but Javascript code can’t execute command into html.
Html is normal, but Javascript code can’t execute command into html.
Html is normal, but Javascript code can’t execute command into html.
Html is normal, but Javascript code can’t execute command into html.
Html is normal, but Javascript code can’t execute command into html.
Html is normal, but Javascript code can’t execute command into html.
Html is normal, but Javascript code can’t execute command into html.

How do I create a date/time till now from a timestamp in hours:minute format (HH:mm) with javascript in React app

From the backend I get a timestamp when a post has been created timestamp : 1688726557.

In my React app I have a list with the latest posts. I have to add the emphasized textdate time till now, like:

  • 10:04 Blog post one
  • 09:38 Blog post two
  • 07:30 Blog post three
    // etc

I am using date-fns in my app. I can’t find a way to do this. With formatDistanceToNowStrict for example:

export const formatTimeToNow = (timestamp: number) =>
  formatDistanceToNowStrict(new Date(timestamp * 1000), {
    unit: 'hour',
    locale: nl,
  });

I get as output 22 uur. So in words instead of hours and minutes HH:mm format?

How do I do this?

An unhandled error occurred processing a request for the endpoint while using createApi(nodejs)

I am using RTK Query for fetching and Caching the data in plain javascript(without react)in nodejs environment.
enter image description here
I am using the above code which is found in the official website of Redux toolkit. The only change is I included fetchFn in fetchBaseQuery because the node-fetch is not detected as a default function. While I am trying to do it, I am facing this error which says
An unhandled error occurred processing a request for the endpoint getPokemonByName
In case of an unhandled error, no tags will be “provided” or “invalidated”. ReferenceError : Headers is not defined

I don’t know how exactly to pass the my own custom fucntion as fetchFn to fetchBaseQuery. I am not sure about the difference between fetchFn and queryFn in createApi. It would be really great if someone can help me out with

  1. Using creatApi with a custom function which takes in url and options as inputs and fetches the data
  2. Using selectors to print the fetched data without using hooks

How do I set cookie in nextjs from a separate backend server

I have a nodejs API built with express.js and the cookie I set work well on postman but it doesn’t seem to work on nextjs. I set the cookie once a user logs-in but it don’t see it on the cookie session of the browser and it is not included in my api request from nextjs.
The cookie set in backend:

 res.cookie("refreshJWT", userRefreshToken, {
      httpOnly: true,
      maxAge: 604800000,
    });

My server cors:

app.use(cors({credentials: true,
    origin: 'http://localhost:3000'
}));

The login in nextjs.

const handleClick = async()=>{
    try {
        dispatch({type: actionEnum.ISLOADING_START});

        const userData = {
            username: logDetails.username,
            password: logDetails.password,
        }
        const response = await axios.post<axiosLogResAttributes>(`${BASE_URL}/login`, userData);
        
            localStorage.setItem('refresh', response?.data.userRefreshToken);
            localStorage.setItem('token', response?.data.userToken)
            dispatch({type: actionEnum.SET_USER_REFRESH, payload: response?.data.userRefreshToken});
            //dispatch({type: actionEnum.SET_IN_MEMORY_VARIABLE, payload: response?.data.userToken})
            
             
            dispatch({type: actionEnum.ISLOADING_END})

          router.push('/')
          
    } catch (error) {
        dispatch({type: actionEnum.ISLOADING_END}) 
    }
    
};

How to set progress bar from 0 to 100% for each uploaded image separately

I want to upload multiple images but in separate XMLHttpRequest
The requests should executes itself sequentially (one by one) and not simultaneously
That’s because I want the progress bar to go from 0 to 100% for each uploaded image

Using this code seems requests executes simultaneously because:

  • progress bar is flickering – constantly goes back and forward
  • all finito in console appears at the same time, i.e. at the end of entire proccess

If I write ajax.open("POST", "a_pro_up.php, false") instead of ajax.open("POST", "a_pro_up.php");:

  • finitos in console appears sequentially
  • but progress bar doesn’t work at all

How to get fluently rising progress bar for each uploaded image separately ?

<input type="file" class='inpfi' id='inpimg' multiple accept="image/jpeg">
<progress class='pbar' id='pbar' value='0' max='100'> 0% </progress>

   inpimg.on('change', function(){
        var files = inpimg[0].files;
        for(var i = 0; i < files.length; i++){
            var file = files[i];
            var fd = new FormData();
            fd.append('id', urw);
            fd.append('upimg', file);
            var ajax = new XMLHttpRequest();
            ajax.upload.addEventListener("progress", up_progress, false);
            ajax.addEventListener("load", up_img_finito, false);
            ajax.open("POST", "a_pro_up.php");
            ajax.send(fd);
        }
    });  

function up_progress(e){
    let percent = (e.loaded / e.total) * 100;
    pbar.val(Math.round(percent));
}

function up_img_finito(){
    console.log('finito');
}

What happens after I input the email password into the browser after trying to launch a received shtml file to view the contents?

I have installed some programming language packages like various javascripts, python, database tools and other types of packages which may be run and now occasionally I receive an shtml file via email which usually looks like a payment and or a receipt in shtml format however when I open the file its asking for my email password in the browser? I assume its alright because its allowed to ask me however I haven’t really been reentering the email password in the browser when prompted to. What happens after entering the email password into the browser after receiving a shtml file? What does it allow me and or the sender of the email to do? I am hopefully it fixes my small fee payments blockers. However maybe its something different? I am concerned there is some sort of lock feature after entering the email password into the browser and some sort of unlock feature?

Email view
Shtml File Exaple
Opening the shtml file in the browser from the email reprompts email password

Please provide more details
https://en.wikipedia.org/wiki/Server_Side_Includes
https://en.wikipedia.org/wiki/List_of_file_formats
What is the purpose and uniqueness SHTML?

Payments and receipts fees features not working. Receiving occasional shtml files suggesting programming fixes in the browser. Concerned that the shtml file may be malicious and or some sort of ransomware. Therefore not reentering the email password as the sender is not branded nicely.

how to check catch block called or not?

I am testing a function using JEST .how to test catch function called or not

here is my code

describe("Loading Tally helper functions", () => {
  let mock;
  beforeAll(() => {
    mock = new MockAdapter(axios);
  });

  afterEach(() => {
    mock.reset();
  });

  describe("fetch Job Order Detail function", () => {
    test("will call getJobOrderDetail function", async () => {
      const users = [
        { id: 1, name: "John" },
        { id: 2, name: "Andrew" }
      ];
      mock.onGet(`/users`).reply(404, null);

      const output = await fetchDetail();

      console.log(output, "pppp");
      // expect(true).toBe(true);
    });
  });
});

function

export const fetchDetail = async (jobNumber) => {
  try {
    const response = await getDetail(jobNumber);
    if (response.data) {
      const jobDetail = response.data;
      if (
        jobDetail &&
        jobDetail.general_details &&
        jobDetail.general_details.job_order_type.value
      ) {
        return {};
      } else {
        return {};
      }
    }
  } catch (e) {
    console.log("Error", e.message);
  }
};

I am sending 404 using this–> mock.onGet(/users).reply(404, null); now I want to check is catch block called or not

https://codesandbox.io/s/friendly-parm-vtczcs?file=/src/helper.js:35-466

I keep getting undefined when running .find() in react component

I’m importing an entire folder of images at the top-level:

const images = require.context('./imgs', false);
const imageList = images.keys().map(image => images(image));

and I have a variable that contains one of the images path’s. (staticImg.value)
I’m trying to match that variable with the corresponding image in the imageList:

const imageItem = imageList.find(image => image.endsWith(staticImg.value.toString()));

but it keeps returning undefined.

this is the console log for all of them:

console.log(imageList);
console.log(staticImg.value);
console.log(imageItem);

ndsectask.js:467 (4) ['/static/media/43bce663-066b-4e55-b322-8c86410c4b16.9580b3807bcba5a3d1aa.png', '/static/media/ab8d6c13-29dd-40fe-95bc-f0c6e04705c1.4f532b80fd144a86a5f0.png', '/static/media/e74cf64a-406d-49b3-a241-98b2d368d509.9ce853d8a1e419d7f38d.png', '/static/media/fe8b78fa-50f5-4061-bf09-1932fc2f0beb.9ce853d8a1e419d7f38d.png']
ndsectask.js:468 fe8b78fa-50f5-4061-bf09-1932fc2f0beb.png
ndsectask.js:469 undefined

What am i doing wrong here?

The aim is to get that exact image and put it in an <img src{} /> tag.

Javascript fullcalendar version 1.6.4 annotation is not working as it is working in 1.5.4 version

$(“#calendarDiv”).fullCalendar({
header: {
left: ‘prev,today,next,agendaWeek,month’,
right: ‘title’
},
customButtons: {
myCustomButton: {
text: ‘custom!’,
click: function() {
alert(‘clicked the custom button!’);
}
}
},
columnFormat: {
week: “ddd – d”,
viewRender: function(view, element) {

      }
  },
  titleFormat: {
      week: "MMMM yyyy"
  },
  firstHour: 9,
  firstDay: 1,
  height: 947,
  defaultView: 'agendaWeek',
  editable: false,
  selectable: true,
  selectHelper: true,
  slotMinutes: 15,
  allDaySlot: false,
  select: function(start, end, allDay) {
    let modifyParam = self.autoSelectStartTimeEndTime({'start': start,'end': end});
    self.commonService.setCalendarParam({'start': modifyParam.start,'end': modifyParam.end});
    self.preSelectCheck({'start': start,'end': end,'flag': 0});
  },
  eventClick: function(calEvent, jsEvent, view) {
    if (calEvent.title != 'Break Time') {
      self.commonService.setCalendarParam(calEvent);
      self.openTimesheetForm(calEvent)
    }
  },
  events: function(start, end, callback) { 
    self.getCalendarEvents({'start': start,'end': end},callback);
  },
  annotations: this.annotationData

});

annotation is not showing on calendar, is there any other way to showing it ?

I tried upgrading fullcalendar version 1.5.4 to 1.6.4 but only annotation is not working

Why requestAnimationFrame not working as expected? [duplicate]

I watched this lecture by Jake Archibald at JSconf where he explained about event loops, render steps, requestAnimationFrame etc.
So, I tried out his code of translating a box from 1000px to 500px. But the solution he gave is not working. It’s still translating from 0px to 500px. What am I doing wrong?

Here is the code I tried:

var box = document.getElementById("box");
var button = document.getElementById("b1");

button.addEventListener("click", () => {
  box.style.transform = "translateX(1000px)";
  box.style.transition = "transform 1s ease-in-out";
  requestAnimationFrame(() => {
    requestAnimationFrame(() => {
      box.style.transform = "translateX(500px)";
    });
  });
});

#box{
  height:100px;
  width:100px;
  background:#000;
}

<div id="box"></div>
<button id="b1">click me!</button><div id="box"></div>
<button id="b1">click me!</button>

Here is the codepen if you wanna see it in action.

I am working on a navbar but the problem is at width 991 of responsive my brand name comes at the center. Help me fix it

………HTML……….

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Document</title>

<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">

<link rel="stylesheet" href="Style.css">

</head>

<body>

<nav class="navbar bg-body-tertiary fixed-top navbar-expand-lg">

<div class="container-fluid">

<button class="navbar-toggler" data-bs-toggle="collapse" data-bs- target="#navbarSupportedContent">

<span class="navbar-toggler-icon"></span>

</button>

<div>

<a herf="#" class="navbar-brand">Brand Name</a>

</div>

<form class="d-flex" action="">

<input class="form-control me-2 " type="search" placeholder="Search">

<button class="btn btn-outline-success" type="submit">Search</button>

</form>

</div>

<div class="collapse navbar-collapse" id="navbarSupportedContent">

<div class="navbar-nav">

<a class="nav-link" href="#">Home</a>

<a class="nav-link" href="#">Contact</a>

<a class="nav-link" href="#">About Us</a>

</div>

</div>

</nav>

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>

</body>

</html>

………CSS(Style.css)………..

@media ( max-width:991px ){ .navbar-toggler{ position: absolute; top:7px; left: 10px; } .navbar-brand{ position: relative; left: 65px; }}                                            .d-flex{ justify-content: flex-end; }                                                         @media (min-width:992px){ .navbar-collapse{ position: absolute; left: 130px; }}                         .navbar-collapse{ padding:10px ; }

When the page is responsive at width 991 the Brand Name comes at the center of the page but i want to prevent that from happening and keep it in place.

Disable Sticky Keys, after pressing 5 times keycode 16 (SHIFT)

$(document).keydown(function(e) {
  //e.preventDefault();
  if (e.keyCode == 16) {
    $('#click_me').css("background-color", "red");
  }
});

$(document).keyup(function() {
  $('#click_me').css("background-color", "#222");
});
#click_me {
  width: 50%;
  color: #fff;
  background: purple;
  font-size: 1em;
  border-radius: 5px;
  position: absolute;
  padding: 1em;
}

#click_me:active {
  background: green;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.0/jquery.min.js"></script>
<button id="click_me">CLICK ME</button>

Is there a way to stop the “sticky keys” tab from appearing

when I press SHIFT more than 5 times?

I want to do it via javascript or jQuery and not from Accessibility=>Keyboard (Win 11).

I have tried => e.preventDefault(); and return but still doesn’t work.

Thanks

How to load a random favicon every load React

Is there a way to randomly load a new favicon every time the page is reloaded in React? I want to have a list of icons and have one randomly chosen every time the page loads.

In the manifest.json, the favicon loading looks like this:

"icons": [
    {
      "src": "favicon.ico",
      "sizes": "64x64 32x32 24x24 16x16",
      "type": "image/x-icon"
    },
    {
      "src": "logo192.png",
      "type": "image/png",
      "sizes": "192x192"
    },
    {
      "src": "logo512.png",
      "type": "image/png",
      "sizes": "512x512"
    }
  ],

Is there any reasonable way to randomly pick an icon from a set of icons?