當(dāng)前位置:軟件學(xué)堂 > 資訊首頁 > 網(wǎng)絡(luò)編程 > 編程其他 > 復(fù)制標(biāo)題和網(wǎng)址的JS怎么寫

復(fù)制標(biāo)題和網(wǎng)址的JS怎么寫

2012/11/10 10:12:34作者:佚名來源:網(wǎng)絡(luò)

移動端

【實(shí)例名稱】

復(fù)制標(biāo)題和網(wǎng)址的JS怎么寫

【實(shí)例描述】

復(fù)制標(biāo)題和網(wǎng)址有利于用戶方便地拷貝本頁面,并推薦給好友,一般用于求職招聘網(wǎng)站。

【實(shí)例代碼】

<html xmlns="http://www.w3.org/1999/xhtml" > <head>     <title>標(biāo)題頁-學(xué)無憂(www.wangbatian.cn)</title> </head> <body> <input type="button" name="Submit" onClick='toClipBoard()' value="復(fù)制網(wǎng)址,傳給好友"> <script language="javascript"> function toClipBoard() { var clipBoardContent=""; clipBoardContent+=document.title;     //獲取頁面標(biāo)題 clipBoardContent+="\n"; clipBoardContent+=this.location.href; //獲取頁面地址 //將拷貝內(nèi)容存放到剪貼板中 window.clipboardData.setData("Text",clipBoardContent); alert("復(fù)制成功,可以粘貼到你的QQ/MSN上,推薦給你的好友!"); } </script> </body> </html>

【運(yùn)行效果】

 復(fù)制標(biāo)題和網(wǎng)址運(yùn)行效果

【難點(diǎn)剖析】

本例的重點(diǎn)是如何將頁面信息保存到剪貼板中。其中剪貼板“clipboardData”是window對象的一個(gè)屬性。

【源碼下載】

為了JS代碼的準(zhǔn)確性,請點(diǎn)擊:復(fù)制標(biāo)題和網(wǎng)址JS 進(jìn)行本實(shí)例源碼下載 

標(biāo)簽: 復(fù)制  標(biāo)題  網(wǎng)址