Utilizing `.back()` in EJS with the powerful combination of Express and M

I'm having trouble with implementing the .back() feature in this code snippet:

<a onclick=<% this.window.history.back() %>

I keep receiving an error stating "history is undefined," even though there is a history in the window object. Does anyone have any suggestions on how to fix this issue and make it work properly?

Answer №1

In my opinion, a more effective solution would be to create a JavaScript function that redirects you without using the "this" keyword.

<a class="go_home" />
const goHomeLink = document.querySelector(".go_home")
const historyGoHome = () => {
    window.location.href = "/"
    goHomeLink.removeEventListener("click", historyGoHome)
}
goHomeLink.addEventListener("click", historyGoHome)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How can I dynamically assign @ViewChild('anchor_name') to a newly updated anchor element in Angular 2+?

Upon receiving an item through a GET request, I set the item_id upon subscription. In the HTML file, I create a div with an anchor id="{{this.item_id}}". However, I encountered the following error: FeedComponent.html:1 ERROR TypeError: Cannot read propert ...

Ways to update the component's state externally

I'm new to Next.js (and React) and I'm attempting to update the state of a component from outside the component. Essentially, I am conditionally rendering HTML in the component and have a button inside the component that triggers a function to se ...

Tips for preparing your response for delivery in Nest.js?

After carefully following the documentation, I successfully implemented an interceptor for response mapping. I am aiming to establish a uniform JSON format for all responses. Is there a more effective way to achieve this rather than using an interceptor? ...

Make sure to use jQuery waterfall 'reflow' only once all the images have finished loading

Currently, I am utilizing jQuery waterfall to achieve a grid-style display on my website. To address the issue of images overlapping, I have enclosed the waterfall method within a .load() function like this: $(window).load(function(){ $('#buildcon ...

Create objects in the gallery

I recently developed a React Material-UI component using Typescript: <Grid container direction="row" justifyContent="flex-start" alignItems="flex-start"> <Grid item xs={5}> <B ...

Event delay with JavaScript and jQuery

In my WordPress (WooCommerce) website, I am working on creating a quantity field... It is functioning properly; however, I want to trigger an event when the + or - buttons next to Quantity are pressed in order to "Update cart". This is what I have tried: ...

Reorganizing socket.io to controller

This is the structure of my application: controller routes.js public jquery.js socket.io.js app.js index.html The app.js file contains a socket program that emits a message when a user connects. The issue I encountered was how to emit the messag ...

"Mastering the Art of Patience: Guarding Your Way Through

When I set up three guards on a route, it appears that all guards are assessed right away. {path: '', component: OptionsComponent, canActivate: [ GuardOne, GuardTwo, GuardThree]} The issue is that I need GuardTwo to wait until GuardOne complete ...

Submit a document from a Vue.js application via an AJAX POST request

Seeking advice on how to upload a file in a VueJS application and send it to a PHP page using jQuery's ajax function. Any assistance would be greatly appreciated. My goal is to achieve this within a VueJS method (the script provided functions correctl ...

"NgFor can only bind to Array objects - troubleshoot and resolve this error

Recently, I've encountered a perplexing error that has left me stumped. Can anyone offer guidance on how to resolve this issue? ERROR Error: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supp ...

Come back and display JSX

I am encountering an issue with a function that is supposed to add JSX to the variable markup. However, when the function is called, the markup is displayed as plain text instead of JSX. How can I ensure that the string is rendered as JSX rather than plain ...

What is the reason behind Next.js inability to import files within a directory?

Error: Module not found - Unable to locate 'components/layout' in nextjs-blog/pages/posts > 1 | import Layout from 'components/layout' 2 | import Link from 'next/link' 3 | import Head from 'next/head' I' ...

Issue with bidirectional data binding in Angular 2 on input element not functioning as expected

Looking at the code snippet below, I have noticed that even though the textchange function is called when the input value changes, the text property of the InputMaskComponent remains constant. I am not able to identify the issue in my code. InputMaskCompo ...

Utilizing Hubot for efficiently parsing JIRA webhooks

In my current project, I am working on decoding a JIRA webhook using a Hubot script. Right now, I have a basic Hubot script that simply displays the posted body: module.exports = (robot) -> robot.router.post '/jirawebhooks/foo-tickets', (r ...

IE encounters an absolute z-index problem when expanding concealed content

I'm having trouble with the positioning of a block (div). I am new to CSS, so any help would be greatly appreciated. Here is the code snippet: http://jsfiddle.net/9rEmt/ (please check it out) for viewing online in IE. When I use absolute for positio ...

Storing and accessing JavaScript arrays in a local JSON file

I am working on a school project and any assistance would be greatly appreciated. Upon execution in a browser like Chrome, the array below gets populated with data. I am trying to determine how to store or update this array in a local file. var listData ...

Tips for incorporating social login into an API

Currently in the process of developing an API using Node.js that is intended to communicate with both a web interface implemented in Angular and a mobile application. I am seeking advice on what authentication technique would be most suitable for enablin ...

Encountering the 502 Bad Gateway Error while utilizing jQuery Ajax POST in conjunction with PHP

My goal is to transfer data to a database using the method outlined below: <script> function add_new_activity(id) { var act_type = $("#add_new_activity #act_type").val(); var act_muscles = $("#add_new_activity #multi").val(); var act_l ...

Utilizing sinon on unit tests for MongoDB in Node.js

My latest project involved creating a model function for mongodb using node-mongodb-native: 'use strict'; const mongo = require('mongodb'); class BlacklistModel { constructor(db, tenant_id, logger) { this._db = db; ...

The Kendo Date Picker is failing to update properly when the k-ng-model is modified

I am facing an issue with my code involving two date pickers and one dropdown list. I want the date pickers to change based on the selected item from the dropdown list. Here is the relevant portion of my code: $scope.toolbarOptions = { i ...