javascript - How to make sure that back button takes me to section where I was there before I clicked an image? - Stack Overflow

I have an HTML page in which there are list of images around 4-5. The HTML code of individual image (it

I have an HTML page in which there are list of images around 4-5. The HTML code of individual image (item-detailponent.html) is shown below:

<span class="badge" id="heart-badge{{item.$id}}">
  <div (click)="badgeHeartEmpty()" id="heartHide{{item.$id}}">
    <img id="badge-item-heart-noborder-empty" src="/assets/images/Empty-Heart.png">
  </div>
  <div [style.display]= " 'none' " (click)="badgeHeartFull()" id="heartShow{{item.$id}}">
    <img id="badge-item-heart-noborder-full" src="/assets/images/Full-Heart-Blue.png">
  </div>
</span>

<!-- This is the code which shows item images and item details -->
<a href="/attendee-item/{{item.$id}}">
    <img class="card-img-top" src="{{item.image_url}}" alt="Card image cap" id="card-img">
    <div class="card-body">
        <div class="auction-item-title">
            <h1 id="auction-item-title">{{item.name}}</h1>
        </div>
        <div class="auction-item-bid-title">
            <div class="auction-item-title-left">
                <p id="auction-item-bid-title">Current Bid: ${{item.bid}}</p>
                <p id="auction-item-bid-title">Value: ${{item.value}}</p>
            </div>

            <div class="auction-item-title-right">
                <p id="auction-item-bid-title2">About this item</p>
            </div>

        </div>
    </div>
</a>
<bid-button [item]="item"></bid-button>


Now if I click above item (as you can see there is a href tag on it) then it shows me detailed description of that image on a new page and that page also has a back button at the top. Below is the code for back button on that new page:

<div class="item-top-bar">
    <div class="item-back-bar">
    <!-- This is the back button and it takes me to home page but instead it should take me to section of image where I was there and clicked it -->
        <p id="item-back-bar-link"><a id="item-back-bar-link" href="/attendee-home"><</a></p>
    </div>
    <div class="item-pagination-bar">
        <a (click)="prevItem()"><p id="item-pagination-bar-text">LAST ITEM</p></a>
        <a (click)="nextItem()"><p id="item-pagination-bar-text">NEXT ITEM</p></a>
    </div>
</div>




Problem Statement:

Now if I click back button then it takes me to the home page but instead what I want is it should take me to the section of image where I was before.

Is this possible to do? I mean if I have may sections of images and if I click lets say 4th image then it will open detailed description of that fourth image page and now if I press back button then it should take me to fourth section of image where I was before.

I have an HTML page in which there are list of images around 4-5. The HTML code of individual image (item-detail.ponent.html) is shown below:

<span class="badge" id="heart-badge{{item.$id}}">
  <div (click)="badgeHeartEmpty()" id="heartHide{{item.$id}}">
    <img id="badge-item-heart-noborder-empty" src="/assets/images/Empty-Heart.png">
  </div>
  <div [style.display]= " 'none' " (click)="badgeHeartFull()" id="heartShow{{item.$id}}">
    <img id="badge-item-heart-noborder-full" src="/assets/images/Full-Heart-Blue.png">
  </div>
</span>

<!-- This is the code which shows item images and item details -->
<a href="/attendee-item/{{item.$id}}">
    <img class="card-img-top" src="{{item.image_url}}" alt="Card image cap" id="card-img">
    <div class="card-body">
        <div class="auction-item-title">
            <h1 id="auction-item-title">{{item.name}}</h1>
        </div>
        <div class="auction-item-bid-title">
            <div class="auction-item-title-left">
                <p id="auction-item-bid-title">Current Bid: ${{item.bid}}</p>
                <p id="auction-item-bid-title">Value: ${{item.value}}</p>
            </div>

            <div class="auction-item-title-right">
                <p id="auction-item-bid-title2">About this item</p>
            </div>

        </div>
    </div>
</a>
<bid-button [item]="item"></bid-button>


Now if I click above item (as you can see there is a href tag on it) then it shows me detailed description of that image on a new page and that page also has a back button at the top. Below is the code for back button on that new page:

<div class="item-top-bar">
    <div class="item-back-bar">
    <!-- This is the back button and it takes me to home page but instead it should take me to section of image where I was there and clicked it -->
        <p id="item-back-bar-link"><a id="item-back-bar-link" href="/attendee-home"><</a></p>
    </div>
    <div class="item-pagination-bar">
        <a (click)="prevItem()"><p id="item-pagination-bar-text">LAST ITEM</p></a>
        <a (click)="nextItem()"><p id="item-pagination-bar-text">NEXT ITEM</p></a>
    </div>
</div>




Problem Statement:

Now if I click back button then it takes me to the home page but instead what I want is it should take me to the section of image where I was before.

Is this possible to do? I mean if I have may sections of images and if I click lets say 4th image then it will open detailed description of that fourth image page and now if I press back button then it should take me to fourth section of image where I was before.

Share Improve this question edited Apr 18, 2018 at 14:56 flash asked Apr 18, 2018 at 5:53 flashflash 1,51913 gold badges73 silver badges160 bronze badges 4
  • 1 yes, it's possible. but what have you tried? – apple apple Commented Apr 18, 2018 at 6:00
  • hey.. I have tried using window history stuff but it doesnt work so thats why I was confuse whether its even possible or not. – flash Commented Apr 18, 2018 at 6:05
  • then you should include it in question. – apple apple Commented Apr 18, 2018 at 6:07
  • window.history stuff have you looked at pushing and popping states the technology is called pushState developer.mozilla/en-US/docs/Web/API/…. – Barkermn01 Commented Apr 26, 2018 at 13:12
Add a ment  | 

8 Answers 8

Reset to default 1

If you want to go back, you should use the back() function in javascript

function goBack() {
    window.history.back();
}
<button onclick="goBack()">Go Back</button>

Here is a small example of how to use it, now you can just adapt it to your page

You can do that by adding the id here

<p id="item-back-bar-link">
   <a id="item-back-bar-link" href="/attendee-home/{{id}}">
       // ....
  </a>
</p>

Now there are multiple way to get the id. You can use the window.location properties or if in same ponent pass this id to a property binding

Here is how I would do it. On a separate note, having the same ID across multiple levels may not be a good idea.

<div class="item-back-bar">
    <!-- This is the back button and it takes me to home page but instead it should take me to section of image where I was there and clicked it -->
        <p id="item-back-bar-link"><a id="back" href="#">Back</a></p>
    </div>

<script>
window.document.getElementById('back').addEventListener('click', function(e){
     window.history.back();
     e.preventDefault();
});
</script>

Angular has Location which is a service that applications can use to interact with a browser's URL. It is what you need in order to solve your problem. See implementation below.

<div class="item-back-bar">
    <!-- This is the back button and it takes me to home page but instead it should take me to section of image where I was there and clicked it -->
        <p id="item-back-bar-link"><a id="back" (click)="goBackClicked()">Back</a></p>
    </div>

Your ts file should have these lines.

import {Component} from '@angular/core';
import {Location} from '@angular/mon';

@Component({
// ponent's declarations here
})
class SomeComponent {
    constructor(private _location: Location) {
    }
    goBackClicked() {
        this._location.back();
    }
}

y not just get the position of the image when it is clicked with .position() and when returned from the image to the page you can get back to the same position with $(window).scrollTop(value).

If your page is scrolled and you want to maintain your scroll position while ing back from the detailed description page, then you can store the current page's vertical scroll position in a service and while navigating back, you can set the scroll position back from service.

Link to ScrollTop in MDN. Also Check Window.To for scrolling.

Sample Angular project to show Element.ScrollTop: https://stackblitz./edit/angular-qdjmny.

Click page1, scroll the sample list to navigate, when u back, the scoll will be maintained.

Also make sure, in your [routerLink] of your detailed description page you are linking to the item-detail.ponent.html ponent.

Really theses ments are right. If you want go back page you can use the mand window.history.go(-1) or window.history.back()

You can use an anchor tag for this. You need to give the part of the page you go back to an "id", like "gobackto_id". Then you can use this in your "" element in the "href" like this:

<a href="http://www.mypage.be/home#gobackto_id". 

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745625256a4636766.html

相关推荐

  • AI驱动的幼儿跌倒检测——视频安全系统的技术解析

    幼儿跌倒检测系统利用AI视频技术,结合人体姿态识别和实时报警功能,提供了一种智能化解决方案。本文将深入剖析其技术架构、模块实现与应用场景,探讨开源技术如何提升幼儿园安全管理。技术架构与实现项目背景幼儿在活动区域(如教室、操场)易发生跌倒,需

    1小时前
    00
  • 文章降 AI 痕迹方法与工具速览

    文章降AI的方法和工具汇总‌如下: 这几天又认真研究类了一下,想让 AI 生成的文章更自然,摆脱程式化痕迹,可尝试以下方法。借助 GPT、文字滚筒鸭,朱雀大模型检测器、豆包、kimi 等大模型,输入文本后,它们能通过调整结构、替换同义词等操

    1小时前
    00
  • MySQL 8.4 配置SSL组复制(八个步骤)

    环境这里有三台MySQL主机,分别是192.168.3.71,72,73,主机名分别对应71.3_mgr1,72.3_mgr2,73.3_mgr3,操作系统均为Oracle Linux 8.10 X64,MySQL版本均为MySQL 8.4

    1小时前
    00
  • 用安信可Ai

    以下作品由安信可社区用户业余菜狗制作前言自从接触智能家居之后,笔者就变得很依赖智能家居(绝对不是懒!)比如卧室灯,就在进门的地方,进门开灯很方便,但是晚上睡觉关灯就很不方便。之前是买了一款Wi-Fi灯,是用手机APP操作,刚开始用的时候感觉

    1小时前
    00
  • MySQL8.4创建keyring给InnoDB表进行静态数据加密

    参考文档:.4enkeyring-plugin-installation.html.4enkeyring-hashicorp-plugin.html#keyring-hashicorp-vault-configuration1.首先

    1小时前
    10
  • MySQL8使用物理文件恢复MyISAM表测试

    我们现场测试一个场景,drop一张MyISAM表后,单独对这表进行物理恢复首先我们看一下secure_file_priv文件目录的位置代码语言:javascript代码运行次数:0运行复制mysql> show global vari

    1小时前
    00
  • AI生态暗战升级,科技巨头铁幕下的终极博弈

    一场围绕AI与智能体的标准、协议及生态的暗战已然蓄势待发。在美剧《权力的游戏》中,不到终局,主角归属始终成谜。如今的AI行业,正上演着同样扣人心弦的戏码。这并非是传统意义上的军事或政治博弈,而是一场围绕AI与智能体的标准、协议及生态展开的暗

    1小时前
    00
  • 电脑分区后进不了系统怎么办,修复教程

    电脑分区后进不了系统&#xff0c;可能的原因有多种&#xff0c;包括分区操作不当导致系统文件丢失或损坏、BIOS设置错误、引导文件未正确配置等。针对这些问题&#xff0c;可以尝试以下解决方法&#xff1

    1小时前
    00
  • UMIT:统一多模态多任务视觉

    随着深度学习的迅速发展,尤其是在医学影像分析领域的应用,越来越多的视觉-语言模型(VLMs)被广泛应用于解决复杂的健康和生物医学挑战。然而,现有研究主要集中在特定任务或单一模态上,这限制了它们在多种医学场景中的适用性和泛化能力。为了解决这

    1小时前
    00
  • 取消Win10开机系统选择倒计时,让电脑秒进系统

    取消Win10开机系统选择倒计时,让电脑秒进系统 近期,不少Win10用户反映在开机时会遇到一个选择系统的倒计时画面,这在一定程度上延缓了开机进程。对于追求高效启动体验的用户来说,这无疑是一个不必要的步骤。那么,如何取消这个倒计时,让电脑

    1小时前
    00
  • 2025年最受欢迎的10款免费CRM软件大对比

    在数字化转型浪潮下,越来越多的企业开始重视客户关系管理(CRM)系统。一个高效的CRM不仅能帮助企业理清客户脉络,还能提升销售效率、优化服务体验。2025年,市场上涌现了众多优秀的免费CRM软件,本文将为大家对比10款最受欢迎的产品,助您选

    1小时前
    00
  • 万字图解 Java 并发框架:ForkJoin、CountDownLatch、Semaphore、CyclicBarrier

    本文图多,内容硬核,建议收藏。在第一章节《1.6w 字图解 Java 并发:多线程挑战、线程状态和通信、死锁;AQS、ReentrantLock、Condition 使用和原理》,我们开启了 Java 高并发系列的学习,透彻理解 Java

    57分钟前
    00
  • 1.8w字图解Java并发容器: CHM、ConcurrentLinkedQueue、7 种阻塞队列的使用场景和原理

    文章多图且内容硬核,建议大家收藏上一章《1.6w 字图解 Java 并发:多线程挑战、线程状态和通信、死锁;AQS、ReentrantLock、Condition 使用和原理》,我们开启了 Java 高并发系列的学习,透彻理解 Java 并

    56分钟前
    00
  • HLS最全知识库

    HLS最全知识库副标题-FPGA高层次综合HLS(二)-Vitis HLS知识库高层次综合(High-level Synthesis)简称HLS,指的是将高层次语言描述的逻辑结构,自动转换成低抽象级语言描述的电路模型的过程。对于AMD Xi

    51分钟前
    00
  • 我用AI监控了奥特曼,当他一发推特AI就会自动给我打电话。

    上周我真的扛不住了。奥特曼这个孙贼,发了个X说,“要发一个礼拜的好东西”。我信了他的邪,明明出差1周,每天早上9点不到就要起来参加活动,但是晚上根本不敢睡觉,天天蹲到凌晨3点半,蹲到他们那边时间中午12点多,我才敢去睡觉。真的,那一整周,我

    49分钟前
    00
  • Power BI 无公式实现帕累托图表

    帕累托分析(Pareto Analysis),也被称为8020法则、关键少数法则,是一种常用的管理工具,用于识别和处理影响业务的主要因素。看到李伟坚老师在Excel使用Vega实现了花式帕累托(参考:Excel 零公式实现高级帕累托图表)

    26分钟前
    00
  • 如何快速判断 Flutter 库是否需要适配鸿蒙?纯 Dart 库无需适配!

    在鸿蒙开发中,选择合适的 Flutter 库至关重要。纯 Dart 库因其跨平台特性,无需适配即可直接使用。但对于新手来说,如何判断一个库是否为纯 Dart 库呢?本文将为你提供清晰的判断方法和实用技巧。一、检查 pubspec.yaml

    23分钟前
    00
  • 什么是docker?它是如何工作的?

    想象一个场景,你要部署一个服务,然后它对环境有很多依赖,不同的操作系统又是不同的需求,而且还可能遇到有些源不能使用,又得一番折腾,折腾完上线后,假设要在新的环境再来一套,又得再来一遍。那么有没有什么办法可以解决呢?有办法,docker就是干

    17分钟前
    00
  • Nat. Mater.

    大家好,今天给大家分享一篇近期发表在Nat. Mater.上的研究进展,题为:De novo design of self-assembling peptides with antimicrobial activity guided

    1分钟前
    00
  • windows新建open ai密钥

    api链接 openai的api需要付费才能使用但好像系统变量不知道为啥用不了打印出来&#xff0c;获取到的是None可以用了

    35秒前
    00

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信