I figured it out. There was nothing wrong with my code. Seems that I might have
discovered a bug. Seems that using the ~= selector doesn't work right. If I'm
getting it right, it should look though a spaced separated list and see if that
list contains the exact value. So if I have:
$("[EMAIL PROTECTED]'external']").click(function(){
return !window.open(this.href);
})
It's looking for any anchor tags with "external" in the rel attribute. Well my
plugin uses that attribute also for it's setting override as shown below:
[a href="/popups/jurisdictions.cfm" class="popup"
rel="height:600,width:310"]click here[/a]
Now the anchor tag above doesn't contain the word "external" in the rel
attribute, but it's still firing.
Just so someone could recreate this and test my findings. Here is my jquery
plugin function:
jQuery.fn.PopUpWindow = function(){
return this.each(function(index){
var setting, href, parameters, newwindow, a, b, c;
a = this.href.split(",");
href = this.href;
settings = {
height:400, // height of window
width:400, // width of window
toolbar:false, // should we show the toolbar
{true,false}
scrollbars:0 // should we show the scollbars {0,1}
};
// overrides the settings with parameter passed in using the
rel tag.
for(var i=0; i < a.length; i++)
{
b = a[i].split(":");
if(typeof settings[b[0]] != "undefined" && b.length ==
2)
{
settings[b[0]] = b[1];
}
}
parameters = "height=" + settings.height + ",width=" +
settings.width + ",toolbar=" + settings.toolbar + ",scrollbars=" +
settings.scrollbars;
jQuery(this).bind("click", function(){
var name = "PopUpWindow" + index;
window.open(href, name, parameters).focus();
return false;
});
});
};
I'm using the lastest version of jQuery (1.1.2, just downloaded it today)
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of John Resig
Sent: Wednesday, February 28, 2007 2:53 PM
To: jQuery Discussion.
Subject: Re: [jQuery] .attr("href", "javascript:void(0);") not working
Don't use the javascript:void(0) stuff at all, trying this instead:
So remove this line:
$this.attr("href", "javascript:void(0);");
And change this:
$this.bind("click", function(){
var name = "PopUpWindow" + index;
window.open(href, name, parameters).focus();
return false;
});
That should do the trick.
--John
On 2/28/07, Petruzzi, Tony <[EMAIL PROTECTED]> wrote:
> I tried to do that and it still didn't work. I've been at this for quite
> sometime now. Could someone on the outside, try the code in their browser and
> tell me if they get the same error?
>
> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> On Behalf Of Matt Oakes
> Sent: Wednesday, February 28, 2007 2:41 PM
> To: jQuery Discussion.
> Subject: Re: [jQuery] .attr("href", "javascript:void(0);") not working
>
> If your just trying to make the browsers default action from happening just
> use "return false" (No quotes). Works well for me. Sorry if thats not what
> your asking.
>
> Matt
>
> rip747 wrote:
> > I'm trying to rewrite a plugin that I wrote a while back since the
> > code has been lost. Basically this plugin makes it easy to have a
> > link open in a popup window I'm having a problem preventing a new
> > window from opening when using javascript:void(0). Below is the code.
> >
> > jQuery.fn.PopUpWindow = function(){
> > return this.each(function(index){
> > var setting, href, parameters, newwindow, a, b, c, $this;
> > $this = jQuery(this);
> > a = $this.attr("rel").split(",");
> > href = $this.attr("href");
> > settings = {
> > height:400, // height of window
> > width:400, // width of window
> > toolbar:false, // should we show the toolbar
> > {true,false}
> > scrollbars:0 // should we show the scollbars {0,1}
> > };
> >
> > // overrides the settings with parameter passed in using the
> > rel tag.
> > for(var i=0; i < a.length; i++)
> > {
> > b = a[i].split(":");
> > if(typeof settings[b[0]] != "undefined" && b.length
> > == 2)
> > {
> > settings[b[0]] = b[1];
> > }
> > }
> >
> > parameters = "height=" + settings.height + ",width=" +
> > settings.width + ",toolbar=" + settings.toolbar + ",scrollbars=" +
> > settings.scrollbars;
> >
> > /* there seems to be a problem with this code. For
> > some reason browsers don't like
> > * the fact that I'm setting the href to javascript:void(0)
> > here.
> > */
> > $this.attr("href", "javascript:void(0);");
> >
> > $this.bind("click", function(){
> > var name = "PopUpWindow" + index;
> > return !window.open(href, name, parameters).focus();
> > });
> > });
> > };
> >
> >
> > An example of a link:
> > [a href="/popups/jurisdictions.cfm" class="popup"
> > rel="height:600,width:310"]click here[/a]
> > NOTE: I'm using brackets to get Nabble to display the code.
> >
> >
> > So the basic problem is that when you click on the link it will
> > open
> > 2 windows instead of just the pop up. Any ideas on how to fix this?
> >
>
>
> _______________________________________________
> jQuery mailing list
> [email protected]
> http://jquery.com/discuss/
>
> --
> No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.5.446 / Virus Database: 268.18.4/705 - Release Date:
> 2/27/2007 3:24 PM
>
>
> --
> No virus found in this outgoing message.
> Checked by AVG Free Edition.
> Version: 7.5.446 / Virus Database: 268.18.4/705 - Release Date:
> 2/27/2007 3:24 PM
>
>
> _______________________________________________
> jQuery mailing list
> [email protected]
> http://jquery.com/discuss/
>
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/
--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.446 / Virus Database: 268.18.4/705 - Release Date: 2/27/2007 3:24
PM
--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.446 / Virus Database: 268.18.4/705 - Release Date: 2/27/2007 3:24
PM
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/