让用户选择链接打开方式:新窗口or当前
FontSize:
-
+ Date: 2006年4月21日
摘要:
网站链接优化,可以让用户自己选择是当前窗口打开,还是新窗口打开。一个较体贴的用户体验,适合个人博客,个人站,主体正文部分的使用。
资料来源:网络文/佚名
Let visitors decide whether or not will they open link in a new window
让用户决定是在打开链接的时候是以新窗口打开或当前窗口打开。
JS部分代码如下:
提示:您可以先修改部分代码再运行
In the old days of webmasters, target attribute provided control of browsers’ behavior. Web sites were breaking natural flow of the user’s travel from site to site. Users couldn’t go back even if they wanted to and they had difficulties following relations between sites. But webmasters and site owners were afraid that users will forget about their web sites and it was better that the site resides somewhere in the background. The fear of the site owners was justified, as their sometimes pretty poor content couldn’t keep users focused and users often went away in search for relevant content.
Many internet-savvy people expected that the off-site link (link to some other web site) will open in new window. More than often too many windows covered their desktops, so internet-savvy people started using better browsers. Those had some advanced options and were able to give control over the browser back to users. In the mean time, the W3C, which already advised separation of structure, presentation and behavior in a web page, removed all traces of behavior layer from XHTML specs and forced webmasters to find other ways...
Contemporary web professionals use JavaScript to control behavior layer of a web document. Some authors wrote about how to place target attribute to links with DOM. Other authors provided option for a user to decide (examples: 1, 2). Some authors found ways to label links according to file type the link points at. It was a matter of time when some authors will innovate a way to add Open in New Window link after every link in a document.
The Open in New Window link points to the same URL like the original, default link, but opens the page in a new window. It is created with DOM method document.createElement, which is well known in DOM experts’ circles. Example of using this method could be found in this page’s source. If one would be more interested in other DOM methods and examples, she would read some (if not all) of the following articles:
- Unobtrusive JavaScript
- DHTML Utopia: Modern Web Design Using JavaScript & DOM
- Client Side Coding : JavaScript & DHTML Tutorials
- DOM scripting Health and Safety
- JavaScript-enhanced image replacement
- Enhanced Form Widgets
- Reading out the “for” attribute via Javascript
- Fancy
<select>s
原文地址:http://webdesign.maratz.com/lab/new_window_link
版权声明:本文属转载作品,版权属原作者所有。
本文链接地址:http://www.demoseo.com/DemoSeo/Let-visitors-decide-open-way.html
如果你也喜欢本文,记得顶一下,支持我。你的支持是我继续发好文章的最大动力!谢谢!
Other Articles
- Rss Feeds将不再出现在Google SERP中 (2007-11-2 19:38:43)
- CSS hack:区分IE6,IE7,firefox (2007-8-8 17:39:48)
- 常见的WEB2.0网站配色 (2006-11-4 17:34:55)
- 目前较流行的几种lightbox (2006-6-6 2:43:22)
- google排名优化圣经 (2006-6-4 9:23:25)
- 让用户自由调整页面字体大小 (2006-4-19 23:50:21)
- Smart‘back to top’link (2006-4-17 22:22:4)
- Resources for web developers (2006-4-14 9:33:9)
Comments
- [Quote] [Reply] 2 DemoSeo Said,
- 在http://webdesign.maratz.com/lab/new_window_link这个外文的原网站,所示例,对于他自己头部与底部,好像未做任何代码修改,却也没有加DOM
Leave a Comment
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。
此代码给全局的a标签都做了DOM的添加,所以对于菜单,部分连接不需要加此功能,此代码未能实现,需要重新优化修改。