Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Return false not working in IE for some reason 2

Status
Not open for further replies.

krigbert

Programmer
Jun 2, 2005
95
0
0
NO
I'm using this simple script:

Code:
  function openWin(myURL) {   
      window.open(myURL.href, "win"+(new Date()).getSeconds(), 'width=525,height=500,resizable=yes,scrollbars=yes');   
      return false;
  }

and writing the links like this: <a href="link" onclick="return openWin(this);"></a>. Now, this works perfectly fine in both firefox and opera, but when I tried it in IE, what happens is that the link does load in a popup - but the main window also loads the link.

I'm not that experienced in JavaScript and didn't know it behaved differently in IE, so help would be great here.

illustration and webdesign
 
<a href="link" <- your telling IE to load a page called link, replace with href="#"

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
I'm telling it to load unless the user has JavaScript enabled, in which case the script above will return false (hence the headline).

That's on purpose, of course, because I want people who have JavaScript disabled to be able to use the page as well - are you saying this simply isn't possible in internet explorer?

The strange thing is that "return false" works for another script on the page that also works with links - though that script is working with jquery - I don't know if that matters.

illustration and webdesign
 
I'm telling it to load unless the user has JavaScript enabled
how are you, onclick is not conditional to a href location or linked to JS enabled.

Onclick won't work if JS is disabled, but if JS is enabled and onclick is used it doesn't overide the href in IE it does both AFAIK.

I could be wrong, but in my experience IE trigers the href and the onlcick separately and have used this to my advantage on some things.

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Right, seems I have to think differently on this, then. I snooped around a bit and found another script I hacked apart a bit. What I have now would be pretty elegant if only it worked:

Code:
window.onload = function(){ 

  var as,i,popfun
  as=document.getElementById('layer_with_popups').getElementsByTagName('a');

  for (i=0;i<as.length;i++){
       popfun=function(){
         window.open(this.href,'',windowAttributes);
         return false;
  };

  as[i].onclick=popfun;
  as[i].onkeypress=popfun;

}

This way, I have all my popups in the div layer_with_popups as plain old <a>s - but it won't work, and as the n00b I am, I can't see why...

illustration and webdesign
 
krigbert, your original code works for me under IE6.
Here is what I used.
Code:
<html>
<head>
<title></title>
</head>
<script type="text/javascript">
function openWin(myURL) {   
      window.open(myURL.href, "win"+(new Date()).getSeconds(), 'width=525,height=500,resizable=yes,scrollbars=yes');   
    return false;
  }
</script>
<body style="font-family:sans-serif;font-size:12px;">
<a href="test.htm" onclick="return openWin(this);">link</a>
</body>
</html>

Try using my code above and see what happens, it might be some other issue in your page causing it to fail.


At my age I still learn something new every day, but I forget two others.
 
That's weird... this works for me as well, but not in my page.

Here's the whole page:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"  "[URL unfurl="true"]http://www.w3.org/TR/html4/strict.dtd"><html[/URL] lang="en">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="hovedstil.css" rel="stylesheet" type="text/css">
<!--[if IE]><link rel="stylesheet" type="text/css" href="ie.css" /><![endif]-->

<script type="text/javascript" language="javascript" src="jquery-latest.js"></script>
  <script type="text/javascript">
    $(document).ready(function(){
	  $("p.popper").hide(0);
	  $("body").click(function(){$("p.popper").hide(0);});
      $("a.surprise").click(function(){
        $("p.popper").show("slow");
			  return false;		
      });
    });
  </script>
<script type="text/JavaScript">
function openWin(myURL) {   
      window.open(myURL.href, "win"+(new Date()).getSeconds(), 'width=525,height=500,resizable=yes,scrollbars=yes');   
    return false;
  }
</script>
</head>
<body>

<div id="hoved">

  <h1><img src="images/header.jpg" width="750" height="223" alt="header"></h1>
  
  <div id="meny">
  
  <a href="index.htm" tabindex="2"><img src="images/homeS.png" alt="Home"></a><a href="about.htm" tabindex="1"><img src="images/aboutS.png" alt="About"></a><a href="index.htm" class="surprise" tabindex="6"><img src="images/productS.png" alt="Products"></a><a href="services.htm" tabindex="3"><img src="images/serviS.png" alt="Services"></a><a href="contact.htm" tabindex="4"><img src="images/contactS.png" alt="Contact"></a>
  <p id="popper" class="popper"><a style="color:#413020;" href="crepe.htm">Crepe Paper</a><br><a style="color:#413020;" href="alu.htm">Aluminum Foil</a><br><a style="color:#413020;" href="kraft.htm">Kraft Paper</a><br>
  <a style="color:#413020;" href="currogated.htm">Corrugated Paper</a><br>
  <a style="color:#413020;" href="cups.htm">Cups and Doilies</a><br><a style="color:#413020;" href="boxes.htm">Boxes and Bags</a><br><a style="color:#413020;" href="tissue.htm">Tissue Paper</a><br></p>
  </div> <!--meny-->
  
  <div id="innehold" style="background-image:url(images/tissuebg.jpg); background-position:0px 0px; background-repeat:repeat-x; height:620px;">  
<div id="overskrift"><h2><img src="images/prodOver.png" alt="Products"></h2></div>
  
      <div id="id"><p>text</p>
        <div id="prodPics"><span class="style1">Click to enlarge 
    <script type="text/javascript">document.write(' in a new window');</script>
    :</span><br>

      <a href="prodbilder/tissue1s.jpg" onclick="return openWin(this);"><img alt="" src="prodbilder/tissue1l.jpg"></a><a href="prodbilder/tissue2s.jpg" onclick="return openWin(this);"><img alt="" src="prodbilder/tissue2l.jpg"></a><a href="prodbilder/tissue3s.jpg" onclick="return openWin(this);"><img alt="" src="prodbilder/tissue3l.jpg"></a></div>
    </div>
	  
    <div id="fot">text</div><!--fotensfot--></div><!--fot-->
  </div><!--innehold-->
  
</div><!--hoved-->

</body>
</html>

illustration and webdesign
 
Your new code works for me here.
One big difference though is this.
<script type="text/javascript" language="javascript" src="jquery-latest.js"></script>

I cannot load that onto my own system to test, it is possible it is causing a problem. Take it out and try again.

BTW, the language="javascript" piece is not valid for HTML 4.01 Strict and you have an extra </div>. These should not be causing your problem though.


At my age I still learn something new every day, but I forget two others.
 
jquery is a handy little javascript library ( ) that I'm using to make the drop down menu work - seems you're right that it's interfering, though :(

I'd really like to avoid taking it out, so I'll have to try to make the other script work. Thanks for the help so far, though.

illustration and webdesign
 
It may be an error in the library itself such as a missing semi colon is causing code farther down the page to fail.
Watch the Javascript Console in Firefox to see if it reports errors.

Try placing your function higher up the page than the library and see what happens.

It may also be that the library is intercepting calls to the window.open command and piping it through it's own function. If so you might be able to make your call to the library function rather than your own.


At my age I still learn something new every day, but I forget two others.
 
There's a big, overly fancy popup "plugin" to the library, and I don't see a lot of mention of "click" in it either, but then again, I'm no expert.

The error console in ff says nothing (and like I said, it works perfectly fine in ff as well)

illustration and webdesign
 
You know what, I just realized that "target=_blank" is valid html strict :p I feel pretty stupid now. It'd still be nice to have an answer in case I ever have to take up xhtml.

Heaps o' thanks for the help, though :) Stars all around

illustration and webdesign
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top