最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

JavascriptJquery, open a link with a REL tag as if it were clicked? - Stack Overflow

matteradmin7PV0评论

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 badges
Add a ment  | 

3 Answers 3

Reset to default 7

If 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>

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far