[jQuery] .attr("href", "javascript:void(0);") not working
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:
$("a[@rel^='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: discuss-bounces@jquery.com [mailto:discuss-bounces@jquery.com] 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