I want to check if the page is being loaded for the first time, and if it is then display the filter. If I put showFiltermenu() in the pageLoad function then it will show every time the page is loaded but I just want it display the first time. I tried using Page.IsPostBack
but that doesn't display the filter.
<script type="text/javascript">
function showFiltermenu() {
$("#filtermenuDrop").toggle('fold', {}, 500);
}
function closefiltermenu() {
$("#filtermenuDrop").toggle('fold', {}, 500);
}
function pageLoad() {
$("input[rel^='datepicker']").datepicker({
dateFormat: 'dd/mm/yy',
changeMonth: true,
yearRange: "c-50:c+50",
changeYear: true,
showOn: "both",
firstDay: 1,
buttonImage: "../images/icons/buttons/basic1-049-small.png"
});
<% if (Page.IsPostBack)
{ %>
showFiltermenu();
<% } %>
ShadowboxInit();
}
After you have a basic understanding of javascript, you can detect when a page has loaded by using the window. onload event. window. onload = function() { addPageContents(); //example function call. }
What is the best way to make sure javascript is running when page is fully loaded? If you mean "fully loaded" literally, i.e., all images and other resources downloaded, then you have to use an onload handler, e.g.: window. onload = function() { // Everything has loaded, so put your code here };
To check if an element has been loaded on a page before running a script with JavaScript, we can use the mutation observer. to create a MutationObserver instance. Then we call observer. observer with the element we want to observe and an object that sets the items we want to observe,.
The browser loads the html (DOM) at first. The browser starts to load the external resources from top to bottom, line by line. If a <script> is met, the loading will be blocked and wait until the JS file is loaded and executed and then continue.
with localStorage
you can save values like this:
var firstTime = localStorage.getItem("first_time");
if(!firstTime) {
// first time loaded!
localStorage.setItem("first_time","1");
}
no jQuery, no plugins, just pure, beautiful and fast HTML5 API
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With