[英]javascript onclick window.open automatically fires
The problem here is that whenever I open the page. 这里的问题是,每当我打开页面时。 the link is automatically opens, sometimes it opens 3 new windows without clicking the div
链接会自动打开,有时会在不单击div的情况下打开3个新窗口
<div onTouchTap={window.open(a)}> TEST </div>
can you please provide your input? 您能提供您的意见吗? or suggest any other alternatives.
或提出其他选择。 by the way I am using ReactJS
我正在使用ReactJS
You need to provide a function to the onTouchTap, you are actually executing window.open(a)
. 您需要为onTouchTap提供一个函数,您实际上是在执行
window.open(a)
。
You could do something like: 您可以执行以下操作:
<div onTouchTap={() => window.open(a)}> TEST </div>
I describe a similar solution and some of the caveats in another answer: 我在另一个答案中描述了类似的解决方案和一些注意事项:
https://stackoverflow.com/a/37771414/350933 https://stackoverflow.com/a/37771414/350933
It's very common mistake. 这是很常见的错误。 There must be a function
() => {window.open(a)}
or window.open.bind(null, a)
as onTouchTap handler, but you are trying to put function call here, so it calls every time when your div rendering 必须有一个函数
() => {window.open(a)}
或window.open.bind(null, a)
作为onTouchTap处理程序,但是您尝试将函数调用放在此处,因此每次在div时都会调用渲染
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.