How to fix progress resetting when i switch my tabs - javascript

Im making a game with tabs and as it stands progress between tabs resets when I change tabs http://prntscr.com/ns2jvg http://prntscr.com/ns2k31 http://prntscr.com/ns2k74 I know eventually i'll make a last tab called options that you can use to reset. but i would like for development to be able to debug and be able to switch tabs with no reset
Im not sure how this is done im new to html
This is my Home Tab in html:
<html>
<head>
<title> Basic Clicker</title>
<link rel="stylesheet" href="css/style.css" />
</head>
<body>
<div class="nav_bar">
<ul>
<li>Home</li>
<li>SkillTree</li>
<li>Equipment</li>
<li>Pets</li>
<li>Skills</li>
<li>Quests</li>
</ul>
</div>
<div class="main_container">
<p>
<html>
<head>
<link rel="stylesheet" type="text/css"
href="interface.css" />
</head>
<title> Basic Clicker</title>
<body>
This is the next tab in html:
<html>
<head>
<title> Basic Clicker</title>
<link rel="stylesheet" href="css/style.css" />
</head>
<body>
<div class="nav_bar">
<ul>
<li>Home</li>
<li>SkillTree</li>
<li>Equipment</li>
<li>Pets</li>
<li>Skills</li>
<li>Quests</li>
</ul>
</div>
<div class="main_container">
<p>
<html>
<head>
<link rel="stylesheet" type="text/css"
href="interface.css" />
</head>
<title> Basic Clicker</title>
<body>
I expect the tabs to switch and for the player to not lose any data/ it not to reset. right now things reset when you click a different tab.

You can make use of localStorage.
On page one you can add an item into localStorage with:
localStorage.setItem('pet', 'Cat'); // name, value
And on page two you can retrieve the value with:
var pet = localStorage.getItem('pet');
You can also overwrite the value later on, or remove it with:
localStorage.removeItem('pet'); // remove an individual item
localStorage.clear(); // remove all items
Note that localStorage persists across browser sessions. If you want to restrict the storage to an individual session, you should instead make use of sessionStorage.

Related

Jquery not loading local html file

I have looked around but still can't get my code to load my html file. From my index.html file I have:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>David Anderson, Georgia Tech Professor</title>
<link rel="stylesheet" href="Assets/Stylesheets/default.css">
<link rel="stylesheet" href="Assets/Stylesheets/header.css">
<link rel="stylesheet" href="Assets/Stylesheets/body.css">
<link rel="stylesheet" href="Assets/Stylesheets/footer.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$('#header').load('header.html');
alert("Does this load!!!??")
</script>
</head>
<body>
<div id="header"></div>
<section class="section_2 index_section">
...
</section>
...
</body>
</html>
And such.
I included the alert for debugging purposes and it works fine, but it never loads my header.html file. I have included both files in the same directory and level.
My header.html includes:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" href="Assets/Stylesheets/default.css">
<link rel="stylesheet" href="Assets/Stylesheets/header.css">
<link rel="stylesheet" href="Assets/Stylesheets/body.css">
<link rel="stylesheet" href="Assets/Stylesheets/footer.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<!------------
- Header -
------------->
<header class="section_1" id="header">
<img src="Images/David's_typical_Profile_Picture.jpg" alt="David Anderson" id="prof_pic">
<h1 id="name_plate">
<a class="name_plate" href="about.html">David Anderson</a>
</h1>
<h2 id="institution_name">
Georgia Institute of Technology
</h2>
<nav id="main_nav">
<ul class="semantic_list">
<li>Home</li>
<li>Courses
<ul>
<li>ECE 6254</li>
<li>ECE 6271</li>
</ul>
</li>
<li>Lab</li>
<li>Consulting</li>
<li>About</li>
</ul>
</nav>
</header>
</html>
I have looked around everywhere, including Adding jQuery to sublime text 2, Why does jQuery or a DOM method such as getElementById not find the element?, https://learn.jquery.com/using-jquery-core/document-ready/ as well as websites about writing/including javascript: https://www.sitepoint.com/community/t/multiple-pages-without-repeating-the-site-structure/8251/3, https://www.sitepoint.com/community/t/calling-multiple-htmls-into-single-html-file/216583/2, but I still run into the same problem, where it simply doesn't load header.html. Ever.
I am loading it on safari using a local path, not a website.
If anyone has a solution/or answer I'd be very grateful.
Thanks!

How do I end my grid of images after a certain amount and add extra pages to scroll through?

I'm struggling to figure out what this is called, so I can't find any online tutorials for implementing this. I have a grid of images on my graphic design portfolio, but the length is getting out of hand. After a certain amount of rows, I'd like to create multiple pages to scroll through. An example of this is seen at the bottom of this designer's grid: https://risarodil.com/
Does anyone know what this effect is called? I assume it's created using js.
If I am understanding this correctly, you are thinking of pagination.
An example shown below.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h2>Pagination - Active State</h2>
<p>Add class .active to let the user know which page he/she is on:</p>
<ul class="pagination">
<li>1</li>
<li class="active">2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ul>
</div>
</body>
</html>

Position a bootstrap dropdown menu on a different control

Is it possible to move the dropdown menu from a bootstrap dropdown-menu to be below a different control? (An input in my case.)
The dropdown is usually based off the button that causes it to dropdown.
The idea is that I have a user that is going to put a value into the input box and then press the button and there will be some floating search results in the "dropdown-menu" box that they can select from.
It will look odd for my UI to have that positioned from the button.
I can create my own popup, but I would rather just use the dropdown-menu if it supports this.
<!DOCTYPE html>
<html>
<head>
<title>Web page template</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown"><input type="text" placeholder="blabla"></a>
<ul class="dropdown-menu">
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
</ul>
</div>
</body>
</html>
Isn't this what you are trying to achieve or maybe I didn't understand your intentions clearly enough? You can always include any kind of element in a link tag and position your menu with CSS.

JavaScript is not working in the html when the html is executed from a link

I have two simple html files which has a link in body and a log in JavaScript. In A.html, it is a link to jump to B.html and a console.log("a 123"); in JavaScript. However, the "a 123" message will only be showed when refresh the browser but not be executed from a link. For example, if i click the link Go to a in b.html, the message "a 123" will not be showed.
Any idea?
-----A.html-------
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href='https://fonts.googleapis.com/css?family=Roboto:400,300' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
<style>
</style>
</head>
<body>
<div data-role="page" id="a">
<div data-role="main" class="ui-content">
<a href='b.html'>Go to b</a>
</div>
</div>
<script>
console.log("a 123");
</script>
</body>
</html>
-----B.html-------
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href='https://fonts.googleapis.com/css?family=Roboto:400,300' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
<style>
</style>
</head>
<body>
<div data-role="page" id="b">
<div data-role="main" class="ui-content">
<a href='a.html'>Go to a</a>
</div>
</div>
<script>
console.log("b 123");
</script>
</body>
</html>
Bit of searching and I found the answer! Apparently it's a 'feature' of Jquery Mobile. It's using an Ajax navigation system. So it stays singlepage.
From the docs:
jQuery Mobile includes a navigation system to load pages into the DOM via Ajax, enhance the new content, then display pages with a rich set of animated transitions. The navigation system uses progressive enhancement to automatically 'hijack' standard links and form submissions and route them as an Ajax request.
Maybe it's a good idea to read the intro of jQuery mobile: http://demos.jquerymobile.com/1.4.5/intro/
That's because the code your code only executes on the page load. If you want it to execute on an event, you need to wrap it in a function and call the function in the onclick attribute on your link.

Jquery mobile dynamic fields not applying styles?

Hi i have creates a html page that creates dynamic fields and when i add them to the listview, it doesnt apply the jquery mobile themes.
here is my javascript:
//Dynamically load data fields for items
$(document).on('pagebeforeshow', '#claimPagefields', function(){
//trigger a create event
$('#claimPagefield').trigger('create');
loadFields();
});
Here is my HTML page
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title></title>
<link href="src/jquery.mobile-1.3.1.min.css" rel="stylesheet" type="text/css"/>
<link rel="stylesheet" href="src/jquery.mobile.iscrollview.css" />
<link rel="stylesheet" href="src/jquery.mobile.iscrollview-pull.css" />
<script src="src/jquery-1.9.1.min.js" type="text/javascript"></script>
<script src="src/jquery.mobile-1.3.1.min.js" type="text/javascript"></script>
<script src="src/iscroll.js"></script>
<script src="src/jquery.mobile.iscrollview.js"></script>
<script src="src/script/itemFields.js"></script>
<link rel="stylesheet" href="src/jquery.ui.datepicker.mobile.css" />
<script src="src/jquery.ui.datepicker.js"></script>
<script src="src/jquery.ui.datepicker.mobile.js"></script>
</head>
<body>
<div data-role="page" id="claimPagefields">
<div data-role="header" data-position="fixed" data-theme="b" data-tap-toggle="false" data-transition="none" > Back
<h1>New Claim</h1>
</div>
<div data-role="content">
<ul class="ui-li" data-role="listview" id="claimTypelistfields" data-inset="true" data-scroll="true">
<li data-role="list-divider">
<h2 id="itemTitle">Title</h2>
</li>
</ul>
<div data-role="navbar">
<ul>
<li>Save</li>
</ul>
</div>
</div>
</div>
</body>
</html>
It doesnt apply the theme on the input fields itself which typically look like this when i am adding it
listItem = '<li id="reasons">' +
'<h3>Reasons:</h3>' +
'<div data-role="fieldcontain">' +
'<input type="text" name="reasons" id="textFieldReasons" value="" />' +
'</div>' +
'</li>';
$('#claimTypelistfields').append(listItem);
$('#claimTypelistfields').listview('refresh');
If i manually add this snippet of code to the above input field manually
style="width:100%"
It works and resizes the width only but i am trying to see if there is way to apply it once instead of having to apply the themes all manually for each field!
Thanks
This is because:
$('#claimTypelistfields').listview('refresh');
will enhance only listview widget and only it. Every non-listview widget added to a listview will not be enhanced.
Basically you will make it work if you use this line:
$('#claimPagefield').trigger('pagecreate');
after the content has been added.
One more thing, in your current code, this line:
$('#claimPagefield').trigger('create');
will not do anything, mainly because you are calling it before new content is appended and second thing, because #claimPagefield is a page id you must use pagecreate instead of create. Create works only on content div.
I finally found the solution.
this code below did the trick as you need to first refrsh and then call teh create trigger all in one line
$('#claimProfileListView').listview('refresh').trigger("create");

Categories