Javascript DOM 编程艺术: popUp
2012-08-23 23:45
337 查看
JavaScript uses the open() method of the window object to create new browser windows. The method takes three arguments:
window.open(url,name,features)
All of the arguments are optional. The first argument is the URL for the document you want to open in a new window. If this is missing, an empty browser window will be created. The second argument is the name that you can give this newly created window. You can use this name in your code to communicate with your newly created window.
Here’s an example of a typical function that uses window.open():
<a href="#" onclick="popUp('http://www.example.com/');
➥ return false;">Example<a>
One way of calling the popUp function is to use what’s known as a pseudo-protocol.
Real protocols are used to send packets of information between computers on the
Internet. Examples are http://, ftp://, and so on. A pseudo-protocol is a non-standard
take on this idea. The javascript: pseudo-protocol is supposed to be used to invoke
JavaScript from within a link.
Here’s how the javascript: pseudo-protocol would be used to call the popUp function:
<a href="javascript:popUp('http://www.example.com/');">Example</a>
This will work just fine in browsers that understand the javascript: pseudo-protocol.
Older browsers, however, will attempt to follow the link and fail. Even in browsers that
understand the pseudo-protocol, the link becomes useless if JavaScript has been disabled.
In short, using the javascript: pseudo-protocol is usually a very bad way of referencing
JavaScript from within your markup.
假若浏览器不支持js,怎么办?一种更好的处理方式:
<a href="http://www.example.com/" onclick="popUp(this.href); return false;">Example</a>
支不支持都可以。
window.open(url,name,features)
All of the arguments are optional. The first argument is the URL for the document you want to open in a new window. If this is missing, an empty browser window will be created. The second argument is the name that you can give this newly created window. You can use this name in your code to communicate with your newly created window.
Here’s an example of a typical function that uses window.open():
function popUp(winURL) { window.open(winURL,"popup","width=320,height=480");
<a href="#" onclick="popUp('http://www.example.com/');
➥ return false;">Example<a>
}
One way of calling the popUp function is to use what’s known as a pseudo-protocol.
Real protocols are used to send packets of information between computers on the
Internet. Examples are http://, ftp://, and so on. A pseudo-protocol is a non-standard
take on this idea. The javascript: pseudo-protocol is supposed to be used to invoke
JavaScript from within a link.
Here’s how the javascript: pseudo-protocol would be used to call the popUp function:
<a href="javascript:popUp('http://www.example.com/');">Example</a>
This will work just fine in browsers that understand the javascript: pseudo-protocol.
Older browsers, however, will attempt to follow the link and fail. Even in browsers that
understand the pseudo-protocol, the link becomes useless if JavaScript has been disabled.
In short, using the javascript: pseudo-protocol is usually a very bad way of referencing
JavaScript from within your markup.
假若浏览器不支持js,怎么办?一种更好的处理方式:
<a href="http://www.example.com/" onclick="popUp(this.href); return false;">Example</a>
支不支持都可以。
相关文章推荐
- 《JavaScript Dom 编程艺术》: 优美 DOM 编程
- 《Javascript DOM 编程艺术》一个练习
- JavaScript DOM 编程艺术(第2版)读书笔记(JavaScript的最佳实践)
- 《JavaScript DOM 编程艺术2》 笔记摘抄
- 《JavaScript DOM 编程艺术》 ——笔记
- 《JavaScript DOM 编程艺术 》 笔记
- JavaScript DOM 编程艺术 第八章 例子分析
- 《JavaScript DOM 编程艺术》 读书笔记
- Javascript DOM 编程艺术:优雅降级
- JavaScript DOM 编程艺术第二版【笔记-第一课】
- Javascript Dom 编程艺术
- 关于《JavaScript DOM 编程艺术》一书中getHTTPObject.js 的一点看法
- Javascript DOM 编程艺术(second edition) 读书笔记(3)
- Javascript Dom 编程艺术 abbreviation
- 《JavaScript DOM 编程艺术》阅读笔记Part B
- 《JavaScript DOM 编程艺术》阅读笔记Part D
- 《Javascript DOM 编程艺术》
- 《JavaScript DOM 编程艺术》小结(一)
- 《JavaScript DOM 编程艺术》(第2版)之读后感悟
- 《Javascript DOM 编程艺术》