Posts by Lauro Moraes • 3,871 points
143 posts
-
1
votes1
answer60
viewsA: How can I perform a function only once in a period of time
Following the logic you intend to apply: the script must be executed once every 24hs period its function checks if the current day is equal to the billing day (monthly) if it is equal executes I…
-
3
votes1
answer72
viewsQ: Regex how to separate by groups each occurrence
I’m trying to add attributes to a tag tag <a> from a parse of Markdown (markdown => html). In my document markdown i add parentheses and the markup I want right after declaring the links,…
-
1
votes2
answers130
viewsA: What is the best way to capture screen resizing in real time?
There is a better way to get real-time resizing of the screen? The event window.onresize is the only real-time method to capture the setting after resizing the window. I need to know if it’s mobile…
-
2
votes1
answer231
viewsA: Nginx with api Node
Usually the directive upstream should be allocated to the block http {} in the Nginx configuration file (Nginx.conf) ... something like this: Nginx.conf http { ## # node socket upstream ## upstream…
-
4
votes1
answer48
viewsA: How would the code below look in pure Javascript?
You can use .querySelector() to fetch the element and use .addEventListener() to observe the Event "keyup" in the target element (<input>) The passage below expresses this reasoning:…
-
2
votes2
answers709
viewsA: How to get the connection id of a socket on a js Node server?
If your system uses some form of login you probably have some unique identifier. You can pass it from client to socket on server check and if it is valid to assign to socket object, example: //…
-
3
votes3
answers81
viewsA: How to change a specific object into an object array?
Use the method .find() of the matrix and Filter by the reference you want and change the values inside the objects const state = { books: [{name: "Maria", age:"22"},{name:"Roberto", age:20}] }…
javascriptanswered Lauro Moraes 3,871 -
3
votes1
answer179
viewsA: How to pass the return (JSON) of a getJson request within the date where the chart values will be?
If you explicitly need return data from JSON, encapsulate your logic "in this return": var widgetTechnologiesChart = function() { if ($('#kt_widget_technologies_chart').length == 0) { return; } var…
-
0
votes4
answers2938
viewsA: Link without using href
Not unlike the answers "inline" already presented but using window.open() <a onclick="window.open('/','_self', 'noopener')" style="cursor:pointer;">SOpt</a> The difference is by the…
-
4
votes2
answers164
viewsA: use fetch api to present user cards, innerHTML overwrite cards
Use the method .insertAdjacentHTML() instead of .innerHTML The first parameter describes the position, use "afterbegin" to position before the first child. If you want to add "after", use…
-
2
votes1
answer59
viewsA: HTML template in Java
This is because you are adding an event there is an element that has not yet been attached to the document tree (DOM) and therefore "doesn’t exist yet". The following "minimum example" reproduces…
-
3
votes2
answers196
viewsA: How can I test if a Nodejs Response is still alive
According to the documentation of Express 4.x res.end() derives directly from response.end() of the Node core at http.ServerResponse You can check the property response.finished that returns a…
-
6
votes2
answers2558
viewsA: HTTP status for registered user
As there is no convention/standard for the use case presented here, I believe any response is "opinionated" as well as almost all responses presented here in the community regarding the use of…
-
2
votes2
answers2024
viewsA: Return of Request (Node.js)
Your "problem" consists of the fact that this request made by the module is asynchronous i.e.: the request will be made and subsequently you will get a reply, either the body of the request or an…
-
0
votes3
answers198
viewsA: What javascript code can I use to replace all html images with webp extension to png when the browser is Safari?
To be sure to use the elements <picture> and <source> is the most canonical method since modern browsers already support it and decide properly which format to use. However use…
-
1
votes1
answer44
viewsA: Problem with script for BMI calculation
Apparently you’re not getting the values (.value) fields when the function CalculoImc() is being called. For example just add .value its reference to some of its fields as: var peso =…
javascriptanswered Lauro Moraes 3,871 -
1
votes3
answers36
viewsA: Redirect when you have a page click event
You can use "vanilla js" no need for a framework, just add a listener to the "click" event in the document and use .replace() in the object window.location ... See the example below:…
javascriptanswered Lauro Moraes 3,871 -
2
votes2
answers790
viewsA: How do I sort a given array object in alphabetical order?
You can use .map() and .sort() to create a list of names in alphabetical order, example: let crescent = POKEMON["pokemon"].map(object => { return object.name }).sort() And use .slice() to copy…
-
1
votes1
answer306
viewsA: What is the best way to make a function of a "Node" file be called on my HTML5 site?
Unlike NW.js that shares the context of the browser and Node in the same process which allows running packages npm and access the browser’s API in the same file .js, Electron does differently, in…
-
3
votes1
answer2173
viewsA: Take last array object
You can search by length using .length minus 1 that will always return the last item let arr = [ '0', '1', '2', '3', '4', '5'] console.log(arr[arr.length -1])…
javascriptanswered Lauro Moraes 3,871 -
4
votes1
answer191
viewsQ: Webcrypto keys derived from PBKDF2
I’m using PBKDF2 in Webcryptoapi to generate a "derivable" key based on a user input (a password) and derive a key from it AES-GCM. I’m doing a round of tests where: in the first round Gero the keys…
-
0
votes1
answer30
viewsA: Check if Node created with insertAdjacentHTML in a loop is "visible"
Not long after asking I arrived at a satisfactory logic ... a pity it takes to share the result here, but never too late. In the bowels of the matter Initially it was marking classes throughout the…
-
7
votes2
answers2601
viewsA: Link "Share on Whatsapp"
Usually the community tends to close this type of question (related to Whatsapp), erroneously in my opinion. Related questions usually do not understand the function-related API "share" Whatsapp and…
-
7
votes3
answers816
viewsQ: Remove spaces from a string from the second occurrence
Currently I am removing spaces using a simple replace() and adding a space I must preserve between the third and fourth character using substr() let str = 'abc defghijk lmnop qrstuv wx y z' str =…
-
1
votes1
answer740
viewsA: How to capture the return of an AJAX that is inside a function?
The function Ajax is asynchronous ie, it is called and its execution does not block the main flow. You must wait for one or another result of the request (success or error) and then return. You can…
-
0
votes2
answers142
viewsA: How to add two li in a ul dynamically with jQuery?
You can use the pseudo selector :nth-child() once you know from which "child" you want to insert content. $('ul > li:nth-child(2)').after(` <li>3</li> <li>4</li> `)…
-
1
votes3
answers42
viewsA: Doubt about standard JS code
Indentation and spacing between brackets usually define the pattern of code structuring. In development it can be used as a reference to make the code more "clean" and readable by following the same…
javascriptanswered Lauro Moraes 3,871 -
1
votes4
answers3601
viewsA: Check if input file is with file or not
Assign a id and an attribute required to his <input type="file"> and check if it is valid...if you do not have a file, it will not be valid. You can check whether the input is (or not) valid…
-
1
votes2
answers139
viewsA: Ajax with clean url how to use browser back
Since you are loading these pages dynamically the correct would be to use the History API and save this "new state". As you have not posted any code of how you will manage calls (.load()) this…
-
1
votes1
answer179
viewsA: Run js Service Worker function even with browser closed or minimized
Service Worker is a Proxy, it performs functions during the request and then terminates. The Apis Web-Push and Sync can operate in "background" even if the user is not in the bad application, it is…
-
1
votes2
answers174
viewsA: Get type of user connection in javascript
You can use the "Network Information API" available in navigator.connection. The support of this API still this low and desktop (or mobile) browsers like Firefox, Safary and Edge still do not…
-
2
votes3
answers507
viewsA: Hide a div
Bootstrap has a class display abbreviated as "d-{breakpoint}-{value}" you can use it to delimit break-points. <script…
-
1
votes2
answers131
viewsA: Merge php arrays
The problem is the function edit_jstree() you’re making a "loop" and enveloping each item into one {Array} ... could simply declare a {Array} before the foreach() and add key value during the…
-
3
votes1
answer1924
viewsA: How to get the data-value of the data-list
If you are not doing the form treatment with javascript what will be sent in the value of your field <input> will be the option value (this is default) as demonstrated in the code below…
-
0
votes2
answers45
viewsA: Identify if a link points to an image, and add a class
A "pitaco" here, I find more succinct: document.querySelectorAll('a').forEach(link => { if ( /\.(jpg|png|gif)/g.test(link.href) ) { link.classList.add('nova-classe') } // mostrar…
javascriptanswered Lauro Moraes 3,871 -
0
votes2
answers1216
viewsA: Header and html footer with css and jquery for all pages divided into sub-folders
Regardless of which directory you are in js is running if you reference the link to the function .onload() in the "absolute" format it will seek correctly: // definir a base (root) let uri =…
-
0
votes1
answer66
viewsA: Dynamic selects
If this <select> is being mounted dynamically and you want to add more items "dynamically", you should search for the element dynamically: let categorias = [ { id: 001, value: 'imoveis' }, {…
-
1
votes1
answer26
viewsA: Delayed function
Use the method on() jQuery and take the form by id this way just use submit() $('#envia-form').on('click', function() { setTimeout(function() { $('#form-target').submit() }, 3000) }) <script…
-
7
votes2
answers2317
viewsA: What is Xpath and what is it for?
According to the Wikipedia (in free translation): Xpath (XML Path Language) is a query language for selecting nodes from an XML document. In addition, Xpath can be used to calculate values (e.g.,…
-
1
votes2
answers48
viewsA: How do you "memorize" an action on a website?
Assuming that you provide different themes for the user to "customize/choose" to apply different styles in the UI of your site, you can use localStorage() or cookies, both solutions use javascript…
answered Lauro Moraes 3,871 -
1
votes2
answers55
viewsA: Generate dynamic borders
I believe you should store only the entry in one {Array} to be able to filter and find the highest value index... imagining that its entry follows the same order scheme defined by the attribute…
-
0
votes2
answers222
viewsA: How to create a javascript function to check whether a cookie has been saved or not?
Both its functions getCookie() as checkCookie() are saving cookies instead of retrieving them (if any). You are also passing "values" to these functions that actually do not need, the only relevant…
-
0
votes1
answer31
viewsA: (Web|Service) Worker import UMD script - How to check context
Using self I was able to reach the expected result let IsServiceWorkerContext = ( ('WorkerGlobalScope' in self) && ('ServiceWorkerGlobalScope' in self) ) ? true : false, IsWebWorkerContext =…
-
6
votes4
answers40794
viewsA: Convert date from DD/MM/YYYY to YYYY-MM-DD in Javascript
I believe the answer presented by Caique Romero I would like to leave this reply in order to enrich the topic. It seems to me that the author seeks to internationalize his software/system and…
javascriptanswered Lauro Moraes 3,871 -
1
votes1
answer1272
viewsA: How to search and update data with Mongoose?
As quoted in the comments: I don’t know why you’re using async... Right when using async should wait (await) both on the first request (findOneAndUpdate()) and on the second (findOne()). By default…
-
1
votes1
answer354
viewsA: Pass a getJSON value to a variable
The function $.getJSON() is asynchronous, the return of this call will not be immediately resolved...you must "observe" the callback if you want to run something only after having a return. var job;…
-
0
votes1
answer31
viewsQ: (Web|Service) Worker import UMD script - How to check context
How to check if the script is being called from a (Web|Service) Worker? I have been using UMD for a long time and am migrating my projects to support SW ... although I use many features available…
-
0
votes1
answer526
viewsA: Setar localStorage in different Omains
The API localStorage() is executed by the browser on the "Politics of Same Origin" (Same-Origin) so even if the application runs in the same domain (example.com) ports and subdomains are treated as…
-
0
votes1
answer30
viewsQ: Check if Node created with insertAdjacentHTML in a loop is "visible"
I’m looking for fragments of HTML with fetch() and adding to the DOM with the function insertAdjacentHTML() in a loop for()... the function that performs this task is in a Promise() and its return…
-
1
votes2
answers1739
viewsA: Upload multiple images with Multer
Multer is a very flexible library, for your specific case use the option .array(), this option requires the field name and can optionally set a second argument to limit the amount of files.…