OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Why doesn't window.onhashchange work in tampermonkey?

  • Thread starter Thread starter Kulo
  • Start date Start date
K

Kulo

Guest
I'm learning Javascript, and I want to write a simple script in Tampermonkey, which will run when the URL fragment identifier changes. But the following function doesn't work when the identifier change. window.onhashchange doesn't work either. I'm convinced that the func() is not the reason.

Code:
window.addEventListener("hashchange", function (){
    alert("run");
    func();
});

But if I add this function for testing,

Code:
window.addEventListener("click", function (){
   console.log(window.location.hash);
});

The hash printed in the console changes with the identifier every time I click, as expected.

I have no idea if this is my problem or the website or the Tampermonkey.

<p>I'm learning Javascript, and I want to write a simple script in Tampermonkey, which will run when the URL fragment identifier changes.
But the following function doesn't work when the identifier change. <code>window.onhashchange</code> doesn't work either. I'm convinced that the <code>func()</code> is not the reason.</p>
<pre><code>window.addEventListener("hashchange", function (){
alert("run");
func();
});
</code></pre>
<p>But if I add this function for testing,</p>
<pre><code>window.addEventListener("click", function (){
console.log(window.location.hash);
});
</code></pre>
<p>The hash printed in the console changes with the identifier every time I click, as expected.</p>
<p>I have no idea if this is my problem or the website or the Tampermonkey.</p>
 

Latest posts

Top