Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

211
Vistas
How to add target="_blank" in location.assign()

In my JavaScript Project of Notes App, there is a location.assign() to my edit note page. But the problem is, whenever I click the note, it opens in the same tab as the index.html page. I have learned CSS and as far my knowledge, target="_blank" is used to open an anchor tag's link in a new window.

I want my edit.html page to open in a new window while also using location.assign().

Here is the code 👇

notes-app.js (using for managing the index.html page)

document.querySelector("#create-note").addEventListener("click", function (e) {
  const id = uuidv4();

  notes.push({
    id: id,
    title: "",
    body: "",
  });
  saveNotes(notes);
  location.assign(`/edit.html#${id}`);
});

index.html

<body>
    <h1>Notes App</h1>
    <h2>Take notes and never forget</h2>
    <input id="search-text" type="text" placeholder="Filter notes" />
    <select id="filter-by">
      <option value="byEdited">Sort by last edited</option>
      <option value="byCreated">Sort by recently created</option>
      <option value="alphabetical">Sort alphabetically</option>
    </select>
    <div id="notes"></div>
    <button id="create-note">Create Note</button>
    <script src="uuidv4.js"></script>
    <script src="notes-functions.js"></script>
    <script src="notes-app.js"></script>
  </body>

I did not include all the code and I hope that this is enough.

Thanks

Edit: If I need to, please write in comments that how do I transfer it to HTML meaning removing the location.assign() and adding something in the HTML or possibly CSS

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

document.querySelector("#create-note").addEventListener("click", 
  function (e) {
      window.open("http://www.someone.com/","_blank");
 });
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda