Jump to content

opening new window


Elemental

Recommended Posts

Hey Folks, I’m trying to make the following script work in IE7, FF3, Opera9 and Safari3, for Win.The script works fine on IE7 but the other three have an issue with it; I have all fourbrowsers set to open links in a new window.I have the following javascript in an external js document:

function open_win(theUrl){window.open(theUrl,"_blank","toolbar=no,location=no,directories=no,status=no,statusbar=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=600,height=600,screenX=50,screenY=100,top=50,left=100");}

Then I have the following html on several Images, respectfully:

<a href="lrgImg/tallGrass.html", target="_blank"><img id="img01" class="imgBorders" src="../art/lrgImages/tallGrass.jpg" alt="" title="" onclick="open_win(this.href); return false" /></a>

As I mentioned IE7 works fine with this, all the images open according to the function call, the other three, although they open a new window as per the function, do not display the images but rather give me the following…FF3:Firefox can't find the file at /C:/Documents and Settings/ ….. /undefined.Opera9:You tried to access the address file://localhost/C:/Documents%20and%20Settings ….. /undefined, which is currently unavailable.Please make sure ...afari3, for Win:Safari opens with a Blank Page, no message.I’m thinking it has to do with the functions parameters. When I removed the parameter I got thefollowing from EI7, Cannot find 'file:///D:Documents%20and%Settings/ ..... /undefined'. It stillopened the image in a new window, however, but not as the script called for; the other threeacted the same as before.I’ve played with this a bit but to be honest I’m at a loss since my current knowledge, as some ofyou know, is lacking still. I understand the value of the parameter can’t come from the script I’mcalling but rather from another script or the html itself so I’ve tried using the name of the html pageI’m trying to load and the image’s id name; the pages open but not to the specs outlined in thefunction callAny masterful insights on this, please?....Peace,Elemental

Link to comment
Share on other sites

When you write open_win(this.href), this refers to the image. But the image doesn't have an href attribute. In IE, I guess it inherits one from the surrounding <a> element. Move the onclick handler to the <a> element. That's where it really belongs.

Link to comment
Share on other sites

When you write open_win(this.href), this refers to the image. But the image doesn't have an href attribute. In IE, I guess it inherits one from the surrounding <a> element. Move the onclick handler to the <a> element. That's where it really belongs.
Deirdre's Dad,THANK YOU! THANK YOU! THANK YOU!It's the little things like that, that can drive you NUTS!!!Not sure if I'll ask this correctly...So, does the (parameter) need to be specific to an attribute within the tag, element you're placing the function call?I used the img id, at one point, as an argument but that didn't work either, was that because the open_win() function, by it's nature, is looking for a link (<a href="">) element or tag?Peace,Elemental
Link to comment
Share on other sites

You can pass anything as a parameter. But you have to be careful with the 'this' reference. It gets even trickier when you use 'this' in a function in a script. You can get fooled easily into thinking it's something it isn't.In any case, if you ever get weird results and you think a parameter might be the source, alert the parameter just to make sure you know what's really in it. If the parameter is an object property, try alerting just the object (in this case, that would have been 'this') and see what it tells you.I alert things all the time when I'm developing, because I usually learn a whole lot by doing so.

Link to comment
Share on other sites

You can pass anything as a parameter. But you have to be careful with the 'this' reference. It gets even trickier when you use 'this' in a function in a script. You can get fooled easily into thinking it's something it isn't.In any case, if you ever get weird results and you think a parameter might be the source, alert the parameter just to make sure you know what's really in it. If the parameter is an object property, try alerting just the object (in this case, that would have been 'this') and see what it tells you.I alert things all the time when I'm developing, because I usually learn a whole lot by doing so.
Deirdre's Dad, Thank you again, sir. I'll bring the alert function (or query?) to the top of the learning list, right next to EVERYTHING else.But seriously, thank you.Peace,Elemental
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...