有时间的话,每天写一点儿代码,不然真的会生疏的。
最近突然开始学习javascript,新手,绝对的新手,希望老手也多多指教。我就稍微的记录一下,这几天学习的效果和成果的展示。
note:非专业文章,没有参考性。。。
今天用javascript实现的打开新窗口。好的:
贴代码:
<html>
<head>
<title>new document test</title>
</head>
<body>
<h1>open a new window </h1>
<input type="button" οnclick="openNewWindow()" value="open a new window"></input>
<script type="text/javascript">
var newWindow = null;
function openNewWindow(){
//open a new window by using window.open();
newWindow = window.open("","","width=700,height=400");
newWindow.focus();
};
</script>
</body>
</html>
window.open可以在当前的窗口下面直接打开一个窗口。
open()总共有三个参数,第一个是窗口的url就是你要打开到什么地方,第二个是窗口的名字,这个随便了,第三个主要是一些样式,像我就定义了一些窗口的大小,这个是一个空的窗口,什么也没有,可以在第一个参数填入"http://www.baidu.com",这样就可以打开百度的界面了。
第二是:
<html>
<head>
<title>new document test</title>
</head>
<body>
<h1>open a new window </h1>
<input type="button" οnclick="openNewWindow()" value="open a new window"></input>
<script type="text/javascript">
var newWindow = null;
function openNewWindow(){
//open a new window by using window.open();
newWindow = window.open("","","width=700,height=400");
newWindow.focus();
//下面的代码可以设置窗口的内容哦!!!其实就是一个HTML字符串,通过document.wirte(),写入进去的!
var strContent = "<html><body><bdo dir='rtl'>here is your text</bdo>"+
"<p>you have some <del>little</del> <ins>big dicks</ins><p></body></html>";
newWindow.document.write(strContent);
newWindow.document.close();
};
</script>
</body>
</html>
这个是什么效果,大家打开看一下吧。。。
刚刚学习,就出来卖弄,找死哦!!!