We help IT Professionals succeed at work.
Get Started

Javascript window.open through a fuction

supportrp asked
Last Modified: 2012-05-06
I'm trying to pass the value to a function called hideNav on click. The problem is that it executes the code as it loads the page instead of waiting for the user to click on the link. Also, it gives me error: not implemented , Error code: 0.

If I comment out the line containing " thisLink.onclick = hideNav(linkhref);" without quotes I don't get an error but my function will not work. What can be the problem here?
   var theLinks = document.links;
   var thisDomain = window.location.hostname;
   // Edit "theMessage" to your liking
   var theMessage = "You are now leaving this site.  The requested web page will open in a new window.  You may click \"Cancel\" to stop loading the requested page. ";
   // Change "showMessage" to 0 if you don't want the warning to pop up when navigating to external sites.
   var showMessage = 0;
  //Change "hideAddress" to 0 if you don't want to hide the IE address bar
   var hideAddress = 1;
  function updateLinks() {
  for (i=0; i < theLinks.length; i++) {
   var thisLink = theLinks[i];
   var linkhref = thisLink.href;
   if (thisLink.href.indexOf(thisDomain) == -1 && thisLink.href.indexOf("javascript") == -1) { 
     thisLink.target = "_blank";
     //alert("Target"+ i +" is: " + thisLink.href); //for testing purposes
   if (hideAddress == 1){ 
     thisLink.onclick = hideNav(linkhref);
    if (showMessage == 1) {
     thisLink.onclick = confirmNav;
 function confirmNav() {
  return confirm(theMessage);
 //hiding the IE navigation
    function hideNav(passval){
	   window.open(passval, "mywindow", "location=1, status=1, scrollbars=1");
 document.body.onload = updateLinks;

Open in new window

Watch Question
Analyst developer
This problem has been solved!
Unlock 1 Answer and 10 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE