Link to home
Create AccountLog in
Avatar of ddlam
ddlamFlag for Hong Kong

asked on

document.links cannot trigger onClick in Firefox

Oh, let say I am tracing a Facebook application.

I have some hyperlink do not show in document.links[]

I tried to setTimeout() for 5 seconds and retrieve the tree again. The hyperlinks still absent.

So I tried other way, I make a newLink with a onClick function and use document.appendChild(newLink) to append it.

However, I don't know how to trigger onClick since it doesn't show in the document.links[].click

The newLink can add anything but how can I trigger its onClick event????
var yourform = document.getElementById("app1");
var newLink=document.createElement('a');
var pickText=document.createTextNode('text for new link');
newLink.setAttribute('onclick',"fbjs_sandbox.instances.a17326627347.bootstrap();");
newLink.setAttribute('id','linkID');
newLink.appendChild(pickText);
yourform .appendChild(newLink);

Open in new window

Avatar of third
third
Flag of Philippines image

try this,
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Third Santor</title>
<script>
window.onload = function(){
var yourform = document.getElementById("app1");
var newLink=document.createElement('a');
var pickText=document.createTextNode('text for new link');
newLink.onclick = function(){alert('test');};
//newLink.onclick = fbjs_sandbox.instances.a17326627347.bootstrap;  //uncomment this later
newLink.href = '#';
newLink.id = 'linkID';
newLink.appendChild(pickText);
yourform.appendChild(newLink);
}
</script>
</head>
<body>
<form name="app1" id="app1" method="post" action="" onsubmit="return ">
  
</form>
</body>
</html>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of scrathcyboy
scrathcyboy
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of ddlam

ASKER

Thanks third and scrathcyboy, how come facebook know this tricky thing.
I am trying to use simulateClick(). Hope it can find the mouse event.
function simulateClick() {
  var evt = document.createEvent("MouseEvents");
  evt.initMouseEvent("click", true, true, window,
    0, 0, 0, 0, 0, false, false, false, false, 0, null);
  var cb = document.getElementById("checkbox"); 
  var canceled = !cb.dispatchEvent(evt);
  if(canceled) {
    // A handler called preventDefault
    alert("canceled");
  } else {
    // None of the handlers called preventDefault
    alert("not canceled");
  }
}

Open in new window

Avatar of ddlam

ASKER

Yup, MouseEvents works~!
I don't know that I helped any more than third did.  You might want to split points with him at least.