Join the AMA (Ask Me Anything) with the Firefox leadership team to celebrate Firefox 20th anniversary and discuss Firefox’s future on Mozilla Connect. Mark your calendar on Thursday, November 14, 18:00 - 20:00 UTC!

为提升您的使用体验,本站正在维护,部分功能暂时无法使用。如果本站文章无法解决您的问题,您想要向社区提问的话,请到 Twitter 上的 @FirefoxSupport 或 Reddit 上的 /r/firefox 提问,我们的支持社区将会很快回复您的疑问。

搜索 | 用户支持

防范以用户支持为名的诈骗。我们绝对不会要求您拨打电话或发送短信,及提供任何个人信息。请使用“举报滥用”选项报告涉及违规的行为。

详细了解

problem with manual click versus javascript: simulated click

  • 2 个回答
  • 1 人有此问题
  • 1 次查看
  • 最后回复者为 toes314

more options

Hi!

I have been trying to simulate from javascript, a click on a link. Sounds simple, yes?

I have FF configured to open new pages in new tabs, by default. So I'd like the simulated click to open the page pointed to by the link, in a new tab. The way I'm simulating the click does attempt to open the page, but the built-in pop-up blocker treats that as a pop-up. That was a surprise to me!

I've created a couple trivial HTML pages to illustrate the problem.

Although I normally have quite a few "extensions" loaded into FF, I am using a separate very simple FF profile to try to make sure the extensions aren't causing the problem.

The first HTML page I'm using to test is literally this:

<meta charset="US-ASCII"> Click Me! <script type="text/javascript"> document.anchors[0].click() ; </script>


The page in the href is literally just this:

<meta charset="US-ASCII"> GOT IT!

I've also tried an alternative approach with initMouseEvent() and dispatchEvent() with an event sequence like, mouseover, mousedown, mouseup, click, but then nothing at all happens.

I would hope there should be a way to do this in FF that doesn't cause FF to treat the result as a pop-up, even then trying to open a page in another tab. But even if I wanted to configure the pop-up, it doesn't appear possible. I'm doing very simple testing with local pages, using the file: scheme. The file: scheme doesn't appear to be supported by the pop-up blocker.

Any explanation of how to do this in FF would be greatly appreciated!

Hi! I have been trying to simulate from javascript, a click on a link. Sounds simple, yes? I have FF configured to open new pages in new tabs, by default. So I'd like the simulated click to open the page pointed to by the link, in a new tab. The way I'm simulating the click does attempt to open the page, but the built-in pop-up blocker treats that as a pop-up. That was a surprise to me! I've created a couple trivial HTML pages to illustrate the problem. Although I normally have quite a few "extensions" loaded into FF, I am using a separate very simple FF profile to try to make sure the extensions aren't causing the problem. The first HTML page I'm using to test is literally this: <!DOCTYPE html> <html> <head> <meta charset="US-ASCII"> </head> <body> <a id="click_anchor" name="click_anchor" href="file:///home/toes/src/js/got_it.html" target="_blank"> Click Me! </a> <script type="text/javascript"> document.anchors[0].click() ; </script> </body> </html> The page in the href is literally just this: <!DOCTYPE html> <html> <head> <meta charset="US-ASCII"> </head> <body> GOT IT! </body> </html> I've also tried an alternative approach with initMouseEvent() and dispatchEvent() with an event sequence like, mouseover, mousedown, mouseup, click, but then nothing at all happens. I would hope there should be a way to do this in FF that doesn't cause FF to treat the result as a pop-up, even then trying to open a page in another tab. But even if I wanted to configure the pop-up, it doesn't appear possible. I'm doing very simple testing with local pages, using the file: scheme. The file: scheme doesn't appear to be supported by the pop-up blocker. Any explanation of how to do this in FF would be greatly appreciated!

所有回复 (2)

more options

See this pref for the behavior with JavaScript window.open() calls.

A good place to ask advice about web development is at the MozillaZine "Web Development/Standards Evangelism" forum.

The helpers at that forum are more knowledgeable about web development issues.
You need to register at the MozillaZine forum site in order to post at that forum.

more options

Thanks for the info!