Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

199
Views
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 answers
Answer question

0

document.querySelector("#create-note").addEventListener("click", 
  function (e) {
      window.open("http://www.someone.com/","_blank");
 });
about 4 years ago ยท Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
ยฉ 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!