0

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

1 Answers1

1
document.querySelector("#create-note").addEventListener("click", 
  function (e) {
      window.open("http://www.someone.com/","_blank");
 });
Suhasini
  • 91
  • 1
  • 4
  • Hello. I don't think that is gonna work because its not an hosted page. Lemme try. Edit: Thanks, all I did was replace the location and assign words to window open. Thanks S J and arsho. Really means a lot – ScratcherXBOX Jan 21 '22 at 14:37