开发者

How to open a window in background onclick? Any problem with this code?

I have a download site (I host some files for free download) where I want to advertise one of my web projects.

The user clicks a link and must reach the target url (the download page). If possible a second window/tab (advertisement) should open, but in the background. The second window also should have all the browsers features like navigation bar, bookmark button etc.

It ist not vital that the ad window opensbut it is vital that the the user reaches the download page.

I currently have this code:

<a href="new-location.htm" 
target=_blank 
onclick="window.location='http://advertise-me.com';">Link mit Fenster</a>

The idea is that new-location.htm is always opend (even if javascript is turned off), and also in a new window so that it is in the foreground. if possible (onclick) the "old" window is redirected to the project that i want to advertise.

No my worries is that the onclick event and the redirect could "steal" the current window and cause the actual link not to be opened in some brows开发者_JS百科er. Is that possible or is the code I use safe?


Popup blocking behavior is not part of the W3C standard. In practice I think what you've done is safe. If the script doesn't run for any reason I doubt it would affect the href direct. I tried out your snippet in a few browsers and they all exhibit the desired behavior you describe.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜