Pop Under on Click for RSS Feed - Javascript

一世执手 提交于 2019-12-13 07:31:53

问题


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();
});


来源:https://stackoverflow.com/questions/7043587/pop-under-on-click-for-rss-feed-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!