开发者

Opening Pages in New Window

Is there a way to open a page in XHTML without using <开发者_Go百科;a href="page.html" target="_blank"> that is standards compliant?

I'm not using frames, but there are some pages that I want to open in a new window instead of the current one.


You can use javascript's window.open() method. However this could easily be blocked by a pop-up blocker. Why do you not want to use the "_blank" target?


You can use something like this:

<a href="page.html" rel="external">My Page</a>

And then you run this jQuery:

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

This will add the target="blank" to the links and make your HTML validate :)


Most pop-up blockers wont block a pop up that has been requested by the user e.g you click a link and it pops up a window. IF you add an onlick event to your link and a target, the desired effect will work even if JS is turned off although you don't want to use target="_blank"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜