php - 我需要保存在 URL 中的 ID 来更新数据库中的表
问题描述
我在网页上有一个幻灯片,用户点击到下一个。当用户点击时,URL 地址内部的 ID 会发生变化。每次用户切换到下一张幻灯片时,我都需要一种更新表格的方法。我想保存用户的位置,然后在以后重新加载他们的进度。幻灯片代码都在一个 html 页面中。以下 2 个部分(幻灯片)的片段:
<section class="aligncenter">
<span class="background light" style="background-image: url('istudy_slides_images/abstract2.jpg')"/></span>
<div class="wrap" id="slide=6">
<div class="wrap">
<h1>Stress is often defined as when an individual perceives the demands upon them to exceed there perceived ability to cope</h1>
</div>
</section>
<!-- SLIDE 6 -->
<section>
<span class="background" style="background-image:url('istudy_slides_images/balance.jpg')"></span>
<div class="wrap" id="slide=7">
<div class="alignright size-50 bg-trans-dark">
<p class="text-subtitle text-serif">"In the end, it's all a question of balance" - Rohinton Mistry</p><br>
<h3><strong>Balance</strong></h3>
<p>A common source of stress and anxiety is when we lack balance within our lives.</p>
<p><strong>Task Two:</strong> Consider whether you have the correct balance in you're life.<br>Are there any improvements you can make to your life work balance to improve your wellbeing?</p>
</div>
</div>
</section>
checkPointMod
显示 id 的 URL 的屏幕截图(我可以在每次 id 更改时使用它来更新我的数据库中的表吗?任何帮助将不胜感激我已经坚持了一段时间。如果最好的方法要做到这一点,请使用 cookie/会话,有人可以给我一些指导吗?
使用:用于幻灯片的 Webslides.tv https://webslides.tv/#slide=2
解决方案
我可以给出一个通用的方法而不是精确的代码。所以你可以做什么,你可以像这样使用 JavaScript 在 URL 中获取那个哈希参数,
let slideID = window.location.hash
然后您可以使用本地存储来存储该 ID,以便您可以使用它来将用户导航到当前幻灯片,如下所示,
localStorage.setItem('slideid', slideID);
然后在重新加载页面时,您可以slideID
像这样检索
localStorage.getItem('slideid');
推荐阅读
- go - 使用 go sql 在 IN 条件占位符中传递数组数组
- malloc - Malloc中内存分配期间分配大小的意义
- java - 将大型资源文件夹包含到 java 项目中的最佳实践
- php - Yii 1.1:如何设置自定义状态码?
- dart - 使用 Navigator.popUntil 和没有固定名称的路由
- entity-framework - API 查询失败,状态码为 BadRequest:
- swift - 用户在线状态不会自动更新
- python - 在数据框中转换日期,如“Jul 3 215”
- javascript - 为什么这个 JS 倒计时不起作用?
- javascript - 将值从 html 表传递到另一个 html/js