Logo

dev-resources.site

for different kinds of informations.

What would everyone think of a `window.post` variable in JavaScript?

Published at
8/10/2023
Categories
idea
javascript
discuss
webdev
Author
calinzbaenen
Categories
4 categories in total
idea
open
javascript
open
discuss
open
webdev
open
Author
12 person written this
calinzbaenen
open
What would everyone think of a `window.post` variable in JavaScript?

Okay, hear me out because this case may or may not be niche.

The Issue

So, PHP has $_POST, which can access posted form data, which is nice for things that work server-side.
But, what if I wanted my HTML to be a local file, which could run offline; now, let's say I had a form and I wanted to send the data to another file:

<form action="./process_info.html" method="post">
  <!-- ... -->
</form>
Enter fullscreen mode Exit fullscreen mode

I feel like we should have something to PHP $_POST.

The Solution

My solution is window.post, which would either be a generic object, or a map of sorts — or, in classic JavaScript fashion, it could be its own class.
Something like:

<script>
  if(window.post.get("age") < 18) { /* Generic under-18 code. */ }
  else { /* Other code. */ }
</script>
Enter fullscreen mode Exit fullscreen mode

What Exists Currently

Looking at a StackOverflow post I found, one solution seems to be to override the behavior of the submit code and use sessionStorage then redirect; however, there is no real means of (more) effectively accomplishing this.
As GetFree says in a reply to the accepted answer, this is something that would be perfectly viable; not only would this work because the browser already knows the data, but also each local HTML file is treated as its "own server" (kind of), so, in theory, data could be passed to a local file like it could a file on a server, or at least I believe so.

What are your thoughts?

Do you (all) think this is something that could provide benefit?
Would it be worth adding this for local HTML apps?

Thanks for reading!
Cheers!
idea Article's
30 articles in total
Favicon
Dev Diaries: Symbolite
Favicon
How to market your idea intro reality.
Favicon
10 Remote SaaS Business Ideas That Will Let You Travel the World
Favicon
The Best Free Alternative to IntelliJ HTTP Client
Favicon
Дашборд для всего
Favicon
Book a Cook
Favicon
Starting a new project - Probtrix
Favicon
How to Validate a SaaS Idea Before Building an MVP
Favicon
JavaScript in IDE scripting console
Favicon
Wednesday Links - Edition 2024-09-18
Favicon
Hotkeys tool for left-handed mouse user.
Favicon
The Power of Full Project Context using LLM's
Favicon
Exciting Java Project Ideas for Beginners 🚀☕
Favicon
How to Grow Online Business Smoothly
Favicon
Github for Story Writing
Favicon
🔥😎 😱Revolutionizing Developer Productivity
Favicon
Deepening the Understanding: A Refined Exploration of Binary Data Stream Analysis
Favicon
Seeking Insights: Enhancing Social Interactions in Games and Apps
Favicon
Ideas for Mobile Applications
Favicon
Help With Solving an App Idea
Favicon
Creating a Searchable Reading List with Strapi CMS Custom API
Favicon
My Intellij IDEA plugin for Maven support - GMaven
Favicon
Beginner Project Idea to Learn Angular and RxJs
Favicon
Unlocking Computational Efficiency in Event Analysis Through Centroids and Blocks: A Conceptual Exploration
Favicon
Redefining Real-Time Machine Learning with Simple Euclidean Points
Favicon
Decoding Pursuer and Evader Points: A New Framework for Understanding Event Dynamics
Favicon
Utilizing Euclidean Space to Represent Tokenized Sequential Data: A Novel Framework for Advancing AI and AGI
Favicon
What would everyone think of a `window.post` variable in JavaScript?
Favicon
Почему важно вести блог
Favicon
How to Transform Your Idea into an Investment by Crafting an Irresistible Pitch

Featured ones: