Pop Under on Click for RSS Feed - Javascript

2019-09-16 07:56发布

问题:

I want to set up the site so when users click on RSS feed links (which I display in part of the site), the feed link appears in a pop under. It makes sense on the site. It's something my users want.

What I can't figure out is how to populate the rss links that I'm pulling to get them to open in a pop under.

I've got this:

$(document).ready(function(){
 $("a[href^='http']").attr('target','_blank');
}); 

which does open the link in a new window. I can add another line like this:

     $("a[href^='http']").attr('onClick','openpopup()');

but I'm not sure how to craft some javascript that will 1) grab the href from the anchor; 2) replace it with a javascript(void); 3) use that url in something like this:

function openpopup() {
window.open("url","","toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no,status=no,width=1250,height=500,left=250,top=175").blur(); window.focus();}

Any ideas?

回答1:

Not much of a jQuery guy, but this should work

$("a[href^='http']").click(function(event) {
    event.preventDefault(); // prevent the link from opening directly
    // open a pop for the link's url 
    var popup = window.open( this.href , "", "toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no,status=no,width=1250,height=500,left=250,top=175" ); 
    popup.blur();
    window.focus();
});