Solved

onmousedown with IE

Posted on 2001-07-10
2
957 Views
Last Modified: 2008-03-10
Hi to all

I create a table dynamically and place a link in a cell like this:
j=1;
Anchor=document.createElement("A");
Anchor.href='javascript:mylink(' +j+ ');';
Anchor.id = 'MyAnchor'+j;
strAnchor = document.createTextNode(listOfMenus[j].text);
Anchor.appendChild(strAnchor);
Anchor.setAttribute("onmousedown","javascript:changelink(event.button,this,"+j+");");

function changelink(button,objref,j)
{   strServer = "www.myserver.com/";
     switch(button)
     {
     case 1:
     objref.href = strServer + default.htm";
     return true;
     break;
     case 2:
     objref.href = strServer + rightklick.htm;
        return true;
     break;
     case 3:  //Netscape
     objref.href = strServer + rightklick.htm;
     return true;
     break;
     default:
     return true;
     }
}
function mylink(j)
{ //do anything important
 return true;}

Unfortunately this does not work under IE5.5 or 6.0. Under Netscape 6.0 it works very well.
When I klick the right mouse-button on the link in IE nothing happens, not even the changelink() routine will be executed.
The question is then how to set dynamically the onmousedown-Attribute in a way that it works also with IE. Is setattribute() not enough?

Greets Alesch
0
Comment
Question by:alesch
2 Comments
 
LVL 14

Accepted Solution

by:
avner earned 101 total points
ID: 6269129
the set Attribute won't work use :

Anchor.onmousedown=new Function('changelink(event.button,this,"+j+")');
0
 

Author Comment

by:alesch
ID: 6288919
Hi avner

Thanks, it worked.

Alesch

(Sorry for the late message)
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now