Tìm kiếm hỗ trợ

Tránh các lừa đảo về hỗ trợ. Chúng tôi sẽ không bao giờ yêu cầu bạn gọi hoặc nhắn tin đến số điện thoại hoặc chia sẻ thông tin cá nhân. Vui lòng báo cáo hoạt động đáng ngờ bằng cách sử dụng tùy chọn "Báo cáo lạm dụng".

Learn More

window.scrollBy() gets sent back after returning from window.click in `content_script.js`

  • Không có trả lời
  • 1 gặp vấn đề này
  • 4 lượt xem
more options

I'm practicing my Javascript with a very simple static HTML page.

I have a sticky footer on top set with CSS. I attached click events to the page's menu anchor tags to jump to the section in the page. Since the header is fixed, the jumped-to section will be covered by the fixed header's height. Therefore I have something like this in my JS script.

     elemTarget.scrollIntoView(true);
     window.scrollBy(0, -parseInt(fixedHeaderHeight.slice(0, 2)));

I have run this in the debugger and everything works in my script. The page gets scrolled back to header's height. However, when I keep on entering the scripts built-in Firefox I stumble upon a function that register's a click event in `content_script.js`.

this one:

window.addEventListener("click", function(e){

 if ( document.body.classList.contains("js-fbc-prompt-active") ) {
   const activePrompt = findActivePrompt();
   const activePromptTarget = document.querySelector(".fbc-has-badge.js-fbc-prompt-active");
   if ( !activePrompt.contains(e.target) && !activePromptTarget.contains(e.target) ) {
     closePrompt();
   }
 } else {
   contentScriptInit(true);
 }

});

after returning from the function above, window.scrollBy() gets undone, meaning that my section's title gets covered by my fixed header.

Why is this happening? Shouldn't this script NOT intervene with anything that happens in my own script?

I'm practicing my Javascript with a very simple static HTML page. I have a sticky footer on top set with CSS. I attached click events to the page's menu anchor tags to jump to the section in the page. Since the header is fixed, the jumped-to section will be covered by the fixed header's height. Therefore I have something like this in my JS script. elemTarget.scrollIntoView(true); window.scrollBy(0, -parseInt(fixedHeaderHeight.slice(0, 2))); I have run this in the debugger and everything works in my script. The page gets scrolled back to header's height. However, when I keep on entering the scripts built-in Firefox I stumble upon a function that register's a click event in `content_script.js`. this one: window.addEventListener("click", function(e){ if ( document.body.classList.contains("js-fbc-prompt-active") ) { const activePrompt = findActivePrompt(); const activePromptTarget = document.querySelector(".fbc-has-badge.js-fbc-prompt-active"); if ( !activePrompt.contains(e.target) && !activePromptTarget.contains(e.target) ) { closePrompt(); } } else { contentScriptInit(true); } }); after returning from the function above, window.scrollBy() gets undone, meaning that my section's title gets covered by my fixed header. Why is this happening? Shouldn't this script NOT intervene with anything that happens in my own script?

Được chỉnh sửa bởi rostranjj vào