Find the a element from the url and click

  • 2020-03-30 02:37:31
  • OfStack

An example of a previous project: when students were added, there was no class data. Need to automatically jump to the class presentation page.

Problem: students, classes, and so on are put into the iframe of the JSP. The student-managed button is in the menu bar on main.html.

Solutions:

Class management by looking up the parent form by id < A> TAB and click
 
$(window.parent.document).find("#folder_12").click(); 

Later the menu bar changed to dynamic, the menu id is dynamic.

What you want is to get by url. A> , and click.
 
<a id="folder_14" onClick="removeTopMenuCss();switchFolder(this.id);changeContent('classManager/classList.do',this);" onFocus="this.blur()" href="javascript:void(0);" target="mainFrame"> Class management </a> 

What you want to get is the changeContent(' url parameter ') for the onClick method

Directly look at the code:
 
//console.info( $(window.parent.document).find("a") ); 
$(window.parent.document).find("#OutFolder a").each(function (index, domEle) { 
//var s = $(domEle).attr("onclick")+""; 
//var start = s.indexOf (''classManager/classList.do'); 
var str = domEle.attributes.onclick.value;//Use js to get the value of the onclick property and search the url
var start = str.indexOf (''classManager/classList.do'); 
if(start>0){ 
$(domEle).click(); 
} 
}); 

Summary: I have been using jquery to find a way to get the onclick property, use indexOf to always report errors, plus "" space into a string

Related articles: