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

265
Views
Using Greasemonkey/Tampermonkey to replace a div object for an anchor object

Some websites, such as Canon (https://www.usa.canon.com/internet/portal/us/home/about/newsroom/press-releases) have their hyperlinks shortened and embedded in a div object, preventing you from right-clicking and 'opening new tab'. I realised I can stop it by changing the div element to an anchor object.

Specifically, if I replace:

<div style ="cursor:pointer;" on click="window.location.href='/internet

with

<a href = 'https://www.usa.canon.com/internet

The html corrects itself and I can now open the link properly. Through some research, I came across Tampermonkey and I've spent the best part of 4 hours trying to write the 1-2 lines of code I would need to get it do it automatically for all instances on a webpage. Could anyone point to me to a quick resource for figuring this out?

Thank you!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Here is a a basic example based on the mentioned page that you can work on:

// ==UserScript==
// @name            Div to Anchor
// @match           https://www.usa.canon.com/internet/portal/us/home/about/newsroom/press-releases
// ==/UserScript==

// --- template
const temp = document.createElement('a');
temp.target = '_blank';                    // open in a new tab

document.querySelectorAll('div[onclick^="window.location.href="]').forEach(item => {
  const a = temp.cloneNode();
  a.href = item.getAttribute('onclick').slice(22, -2);
  a.textContent = item.textContent;
  item.replaceWith(a);
});
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!