admin管理员组文章数量:1393336
The designer that I am working with on a project implemented a pop-up so that it is called when a static link is clicked like
<a href="#" rel="#dialog">Testing Dialog</a>
Of course, I don't want it as a static link as I have to do things to it before it is shown to the user so I am wondering if anyone knows of a way to make a call with Javascript to do the same thing as if the link above were clicked by the user? Any advice is greatly appreciated
The designer that I am working with on a project implemented a pop-up so that it is called when a static link is clicked like
<a href="#" rel="#dialog">Testing Dialog</a>
Of course, I don't want it as a static link as I have to do things to it before it is shown to the user so I am wondering if anyone knows of a way to make a call with Javascript to do the same thing as if the link above were clicked by the user? Any advice is greatly appreciated
Share Improve this question asked Apr 18, 2011 at 23:09 RickRick 17k35 gold badges113 silver badges163 bronze badges3 Answers
Reset to default 7If I understand correctly, with jQuery:
$("a[rel='dialog']").click();
or:
$("a[rel='dialog']").trigger("click");
Demo: http://jsfiddle/karim79/fc6Yk/
Basic javascript for triggering a click on an element:
var clicky = document.createEvent("HTMLEvents");
clicky.initEvent("click", true, true);
targetElement.dispatchEvent(clicky);
Docs!
- https://developer.mozilla/en/DOM/document.createEvent
- https://developer.mozilla/en/DOM/event.initEvent
- https://developer.mozilla/en/DOM/element.dispatchEvent
For more detailed click events, see: https://developer.mozilla/en/DOM/event.initMouseEvent
div
for js:
function popitup(url) {
newwindow=window.open(url,'name','height=200,width=150');
if (window.focus) {newwindow.focus()}
return false;
}
for html:
<div onclick="popitup()"> When you click this, it will pop up</diva>
本文标签: JavaScriptJQueryopen a link with a REL tag as if it were clickedStack Overflow
版权声明:本文标题:JavascriptJquery, open a link with a REL tag as if it were clicked? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741181873a2353620.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论