Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

222
Views
Page Reload function and after init some functions

I'm acutally creating a reloadPage function, which takes and Id and then reload(load) it. Since after I load the page I couldn't use any functions, so I basically I want to do a init function within.

So here my function

function reloadPage(id) {
    $("#"+id).load(window.location + " #"+id);
 }

and I want to do a init function, so I can call it.

would be like

reloadPage(test, init())

is this possible? How would I approach a problem like that.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

There are many methods to pass data to a page from a previous instance,one of them is WebStorage api

So in order to run a specific block of code when a page loads you could use sessionStorage to store whatever flag you want,and then check if that flag exists and run your desired function,its probably not what you want but since you did not provide a reproducible example ( How do I ask a good question? ),i hope it gives you clues and directions how to implement such functionality to your projects

For example (save this as html,load it and check your console):


<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"
    integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
</head>
<body>
<input>
<button>TEST</button>
<script>
$(document).on('click', 'button', function () { 
let func = $("input").val() //give your desired function here
sessionStorage.setItem("function", func); //store whatever you typed in the session storage
location.reload(); //now reload the page
})

window.onload = function () { //this function runs code after a page completely loads
$("input").val("function 1") //just for the example i set an initial value to the input
let funct = sessionStorage.getItem("function"); // get the data you stored previously

if( funct === "function 1" ){  // check for specific flags
console.log("This is function 1")
}

if( funct === "function 2" ){
console.log("This is function 2")
}

};
</script>
</body>
</html>

You could also learn about Url parameters and pass a query string to your reload url with the value you want to pass.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!