首页 > 解决方案 > How can I stop users from editing the url in a multi-page quiz?

问题描述

I have seen a few different online quizzes/forms where there are multiple webpages used. If you try to skip a page by editing the URL (for example, you are on www.exampledomain.com/pg2 and you edit it to www.exampledomain.com/pg3), it would redirect you back to the page you didn't finish.

I am working on an online game with a different webpage for each level. I would like help finding a way in which I can prevent users from editing the URL of a level and skipping to the next. Is there a way I can code this in JavaScript, jQuery, etc.?

Thanks!

标签: javascripthtmljqueryforms

解决方案


是的,创建一个您想要在每个级别上进行更改的 JavaScript 数组,并在该级别完成时在该数组的帮助下编辑 DOM。可能您可以使用计数器变量在完成一个级别时递增,并将该变量设置为数组索引以获取相应的更改。

每当您制作此类网络游戏时,请尝试添加一些具有某些共同特征的元素,例如,如果它是避障游戏,那么您可能会有共同的墙壁,但它们的排列可能会根据级别而改变。所以我认为即使是你的游戏也会有这样的元素。如果是这样,那么工作就很简单了,你可以在 JavaScript 的帮助下完成一个级别后更改页面的特定元素。

说第 1 级已完成,然后您可以设置用户是否完成任务的条件,如果是,则在 JS 的帮助下创建一个模式屏幕,要求他们继续或离开,如果他们选择继续,则不要' t 使用单独的 HTML 文件来创建下一个级别只需使用 JS 并使用一些方法(如innerHtmlinnerText.


推荐阅读