<thead id="jxdzp"><address id="jxdzp"><pre id="jxdzp"></pre></address></thead>

<em id="jxdzp"><span id="jxdzp"></span></em>

    <listing id="jxdzp"><nobr id="jxdzp"><meter id="jxdzp"></meter></nobr></listing>

      <address id="jxdzp"></address>
      <noframes id="jxdzp"><form id="jxdzp"><th id="jxdzp"></th></form>
      <noframes id="jxdzp"><form id="jxdzp"><th id="jxdzp"></th></form>

          訂閱本欄目 RSS您所在的位置: 深山工作室 > 頁面特效 > 正文

          超級實用且不花哨的js代碼大全( 7 )

          網絡 2009/9/4 8:31:08 深山行者 字體: 瀏覽 7218

          彈窗代碼匯總
          【0、超完美彈窗代碼 】
          功能:5小時彈一次+背后彈出+自動適應不同分辯率+準全屏顯示

          代碼:
          <script>
          function openwin(){
          window.open(http://www.6882.com,"pop1","width="+(window.screen.width-15)+",height="+(window.screen.height-170)+",left=0,top=0,toolbar=yes,menubar=yes,scrollbars=yes,resizable=yes,location=yes,status=yes")
          setTimeout("focus();",5);
          }
          function get_cookie(Name) {
          var search = Name + "="
          var return&#118alue = "";
          if (documents&#46cookie.length > 0) {
          offset = documents&#46cookie.indexOf(search)
          if (offset != -1) {
          offset += search.length
          end = documents&#46cookie.indexOf(";", offset);
          if (end == -1)
          end = documents&#46cookie.length;
          return&#118alue=unescape(documents&#46cookie.substring(offset, end))
          }
          }
          return return&#118alue;
          }
          function Set()
          {
            var Then = new Date()    
            Then.setTime(Then.getTime() + 5*60*60*1000 )
            documents&#46cookie = "popped1=yes;expires="+ Then.toGMTString()
          }

          function loadpopup(){
          if (get_cookie('popped1')=='')
          {
          openwin()
          Set()
          }
          }
          setTimeout("loadpopup()",5);

          </script>


          【1、最基本的彈出窗口代碼】

          其實代碼非常簡單:

          <script language="&#106avascript">
          <!--
          window.open ('page.html')
          -->
          </script>
          因為著是一段&#106avascripts代碼,所以它們應該放在<script language="&#106avascript">標簽和</script>之間。<!-- 和 -->是對一些版本低的瀏覽器起作用,在這些老瀏覽器中不會將標簽中的代碼作為文本顯示出來。要養成這個好習慣啊。
          window.open ('page.html') 用于控制彈出新的窗口page.html,如果page.html不與主窗口在同一路徑下,前面應寫明路徑,絕對路徑(http://)和相對路徑(../)均可。用單引號和雙引號都可以,只是不要混用。
          這一段代碼可以加入html的任意位置,<head>和</head>之間可以,<body>間</body>也可以,越前越早執行,尤其是頁面代碼長,又想使頁面早點彈出就盡量往前放。


          【2、經過設置后的彈出窗口】

          下面再說一說彈出窗口的設置。只要再往上面的代碼中加一點東西就可以了。
          我們來定制這個彈出的窗口的外觀,尺寸大小,彈出的位置以適應該頁面的具體情況。
          <script language="&#106avascript">
          <!--
          window.open ('page.html', 'newwindow', 'height=100, width=400, top=0,left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no')
          //寫成一行
          -->
          </script>
          參數解釋:
          <script language="&#106avascript"> js腳本開始;
          window.open 彈出新窗口的命令;
          'page.html' 彈出窗口的文件名;
          'newwindow' 彈出窗口的名字(不是文件名),非必須,可用空''代替;
          height=100 窗口高度;
          width=400 窗口寬度;
          top=0 窗口距離屏幕上方的象素值;
          left=0 窗口距離屏幕左側的象素值;
          toolbar=no 是否顯示工具欄,yes為顯示;
          menubar,scrollbars 表示菜單欄和滾動欄。
          resizable=no 是否允許改變窗口大小,yes為允許;
          location=no 是否顯示地址欄,yes為允許;
          status=no 是否顯示狀態欄內的信息(通常是文件已經打開),yes為允許;
          </script> js腳本結束


          【3、用函數控制彈出窗口】

          下面是一個完整的代碼。
          <html>
          <head>
          <script language="&#106avascript">
          <!--
          function openwin() { window.open ("page.html", "newwindow", "height=100, width=400, toolbar=
          no, menubar=no, scrollbars=no, resizable=no, location=no, status=no"
          //寫成一行
          }
          //-->
          </script>
          </head>
          <body >
          ...任意的頁面內容...
          </body>
          </html>
          這里定義了一個函數openwin(),函數內容就是打開一個窗口。在調用它之前沒有任何用途。
          怎么調用呢?
          方法一:<body > 瀏覽器讀頁面時彈出窗口;
          方法二:<body > 瀏覽器離開頁面時彈出窗口;
          方法三:用一個連接調用:
          <a href="#" _fcksavedurl=""#"" _fcksavedurl=""#"" _fcksavedurl=""#"" &#111nclick="openwin()">打開一個窗口</a>
          注意:使用的“#”是虛連接。
          方法四:用一個按鈕調用:
          <input type="button" &#111nclick="openwin()" &#118alue="打開窗口">


          【4、同時彈出2個窗口】

          對源代碼稍微改動一下:
          <script language="&#106avascript">
          <!--
          function openwin()
          { window.open ("page.html", "newwindow", "height=100, width=100, top=0,left=0,toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no"
          //寫成一行
          window.open ("page2.html", "newwindow2", "height=100, width=100, top=100, left=100,toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no"
          //寫成一行
          }
          //-->
          </script>
          為避免彈出的2個窗口覆蓋,用top和left控制一下彈出的位置不要相互覆蓋即可。最后用上面說過的四種方法調用即可。

          注意:2個窗口的name(newwindows和newwindow2)不要相同,或者干脆全部為空。ok?


          【5、主窗口打開文件1.htm,同時彈出小窗口page.html】

          如下代碼加入主窗口<head>區:
          <script language="&#106avascript">
          <!--
          function openwin()
          {window.open("page.html","","width=200,height=200"
          }
          //-->
          </script>
          加入<body>區:
          <a href="1.htm" &#111nclick="openwin()">open</a>即可。


          【6、彈出的窗口之定時關閉控制】

          下面我們再對彈出的窗口進行一些控制,效果就更好了。如果我們再將一小段代碼加入彈出的頁面(注意是加入到page.html的html中,可不是主頁面中,否則...),讓它10秒后自動關閉是不是更酷了?

          首先,將如下代碼加入page.html文件的<head>區:
          <script language="&#106avascript">
          function closeit()
          {settimeout("self.close()",10000) //毫秒}
          </script>
          然后,再用<body > 這一句話代替page.html中原有的<body>這一句就可以了。(這一句話千萬不要忘記寫??!這一句的作用是調用關閉窗口的代碼,10秒鐘后就自行關閉該窗口。)


          【7、在彈出窗口中加上一個關閉按鈕】

          <form>
          <input type='button' &#118alue='關閉' &#111nclick='window.close()'>
          </form>

          呵呵,現在更加完美了!


          【8、內包含的彈出窗口-一個頁面兩個窗口】

          上面的例子都包含兩個窗口,一個是主窗口,另一個是彈出的小窗口。

          通過下面的例子,你可以在一個頁面內完成上面的效果。
          <html>
          <head>
          <script language="&#106avascript">
          function openwin()
          {openwindow=window.open("", "newwin", "height=250, width=250,toolbar=no,scrollbars="+scroll+",menubar=no";
          //寫成一行
          openwindow.document.write("<title>例子</title>"
          openwindow.document.write("<body bgcolor=#ffffff>"
          openwindow.document.write("<h1>hello!</h1>"
          openwindow.document.write("new window opened!"
          openwindow.document.write("</body>"
          openwindow.document.write("</html>"
          openwindow.document.close()}
          </script>
          </head>
          <body>
          <a href="#" &#111nclick="openwin()">打開一個窗口</a>
          <input type="button" &#111nclick="openwin()" &#118alue="打開窗口">
          </body>
          </html>
          看看 openwindow.document.write()里面的代碼不就是標準的html嗎?只要按照格式寫更多的行即可。千萬注意多一個標簽或少一個標簽就會出現錯誤。記得用openwindow.document.close()結束啊。
          【9、終極應用--彈出的窗口之cookie控制】

          回想一下,上面的彈出窗口雖然酷,但是有一點小毛病(沉浸在喜悅之中,一定沒有發現吧?)比如你將上面的腳本放在一個需要頻繁經過的頁面里(例如首頁),那么每次刷新這個頁面,窗口都會彈出一次,是不是非常煩人?:-(有解決的辦法嗎?yes! ;-) follow me.

          我們使用cookie來控制一下就可以了。

          首先,將如下代碼加入主頁面html的<head>區:
          <script>
          function openwin()
          {window.open("page.html","","width=200,height=200"}
          function get_cookie(name)
          {var search = name + "="
          var return&#118alue = "";
          if (documents&#46cookie.length > 0) {
          offset = documents&#46cookie.indexof(search)
          if (offset != -1) {
          offset += search.length
          end = documents&#46cookie.indexof(";", offset);
          if (end == -1)
          end = documents&#46cookie.length;
          return&#118alue=unescape(documents&#46cookie.substring(offset,end))
          }
          }
          return return&#118alue;
          }
          function loadpopup(){
          if (get_cookie('popped')==''){
          openwin()
          documents&#46cookie="popped=yes"
          }
          }
          </script>
          然后,用<body >(注意不是openwin而是loadpop?。。┨鎿Q主頁面中原有的<body>這一句即可。你可以試著刷新一下這個頁面或重新進入該頁面,窗口再也不會彈出了。真正的pop-only-once!
          強力彈窗代碼:

          <Script Language="&#106avascript">
          var paypopupURL = "http://23sui.com";
          var usingActiveX = true;
          function blockError(){return true;}
          window.&#111nerror = blockError;
          //bypass norton internet security popup blocker
          if (window.SymRealWinOpen){window.open = SymRealWinOpen;}
          if (window.NS_ActualOpen) {window.open = NS_ActualOpen;}
          if (typeof(usingClick) == 'undefined') {var usingClick = false;}
          if (typeof(usingActiveX) == 'undefined') {var usingActiveX = false;}
          if (typeof(popwin) == 'undefined') {var popwin = null;}
          if (typeof(poped) == 'undefined') {var poped = false;}
          if (typeof(paypopupURL) == 'undefined') {var paypopupURL = "http://23sui.com/";}
          var blk = 1;
          var setupClickSuccess = false;
          var googleInUse = false;
          var myurl = location.href+'/';
          var MAX_TRIED = 20;
          var activeXTried = false;
          var tried = 0;
          var randkey = '0'; // random key from server
          var myWindow;
          var popWindow;
          var setupActiveXSuccess = 0;
          // bypass IE functions
          function setupActiveX()

          {if (usingActiveX)

          {try

          {if (setupActiveXSuccess < 5)

          {document.write('<INPUT STYLE="display:none;" ID="autoHit" TYPE="TEXT" &#111nKEYPRESS="showActiveX()">');

          popWindow=window.createPopup();

          popWindow.document.body.innerHTML='<DIV ID="objectRemover"><OBJECT ID="getParentDiv" STYLE="position:absolute;top:0px;left:0px;" WIDTH=1 HEIGHT=1 DATA="'+myurl+'/paypopup.html" TYPE="text/html"></OBJECT></DIV>';

          document.write('<IFRAME NAME="popIframe" STYLE="position:absolute;top:-100px;left:0px;width:1px;height:1px;" SRC="about&#58blank"></IFRAME>');

          popIframe.document.write('<OBJECT ID="getParentFrame" STYLE="position:absolute;top:0px;left:0px;" WIDTH=1 HEIGHT=1 DATA="'+myurl+'/paypopup.html" TYPE="text/html"></OBJECT>');

          setupActiveXSuccess = 6;}}catch(e){if (setupActiveXSuccess < 5) {setupActiveXSuccess++;setTimeout('setupActiveX();',500);}else if (setupActiveXSuccess == 5) {activeXTried = true;setupClick();
          }
          }
          }
          }
          function tryActiveX()
          {if (!activeXTried && !poped)

          {if (setupActiveXSuccess == 6 && googleInUse && popWindow && popWindow.document.getElementById('getParentDiv') && popWindow.document.getElementById('getParentDiv').object && popWindow.document.getElementById('getParentDiv').object.parentWindow)

          {
          myWindow=popWindow.document.getElementById('getParentDiv').object.parentWindow;
          }

          else if (setupActiveXSuccess == 6 && !googleInUse && popIframe && popIframe.getParentFrame && popIframe.getParentFrame.object && popIframe.getParentFrame.object.parentWindow)

          {
          myWindow=popIframe.getParentFrame.object.parentWindow;popIframe.location.replace('about&#58blank');
          }

          else
          {
          setTimeout('tryActiveX()',200);tried++;
          if (tried >= MAX_TRIED && !activeXTried)
          {
          activeXTried = true;setupClick();
          }
          return;
          }

          openActiveX();
          window.windowFired=true;self.focus();
          }
          }

          function openActiveX()
          {if (!activeXTried && !poped)
          {if (myWindow && window.windowFired)
          {
          window.windowFired=false;
          document.getElementById('autoHit').fireEvent("&#111nkeypress", (document.createEventObject().keyCode=escape(randkey).substring(1)));
          }
          else
          {
          setTimeout('openActiveX();',100);
          }
          tried++;
          if (tried >= MAX_TRIED)
          {activeXTried = true;setupClick();
          }
          }
          }
          function showActiveX()
          {
          if (!activeXTried && !poped)
          {if (googleInUse)
          {window.daChildObject=popWindow.document.getElementById('objectRemover').children(0);
          window.daChildObject=popWindow.document.getElementById('objectRemover').removeChild(window.daChildObject);
          }
          newWindow=myWindow.open(paypopupURL,'abcdefg');
          if (newWindow)
          {
          newWindow.blur();
          self.focus();activeXTried = true;poped = true;
          }
          else
          {
          if (!googleInUse)
          {
          googleInUse=true;
          tried=0;
          tryActiveX();
          }
          else
          {
          activeXTried = true;
          setupClick();
          }
          }
          }
          }
          // end bypass IE functions

          // normal call functions


          function paypopup()
          {if (!poped)
          {if(!usingClick && !usingActiveX)
          {popwin = window.open(paypopupURL,'abcdefg');
          if (popwin)
          {poped = true;
          }
          self.focus();
          }
          }
          if (!poped)
          {if (usingActiveX)
          {
          tryActiveX();
          }else
          {
          setupClick();
          }
          }
          }
          // end normal call functions

          // &#111nclick call functions

          function setupClick()
          {if (!poped && !setupClickSuccess)
          {
          if (window.Event)
          document.captureEvents(Event.CLICK);
          prePaypop&#111nclick = document.&#111nclick;
          document.&#111nclick = gopop;self.focus();
          setupClickSuccess=true;
          }
          }


          function gopop()
          {if (!poped)
          {
          popwin = window.open(paypopupURL,'abcdefg');
          if (popwin)
          {
          poped = true;
          }
          self.focus();
          }
          if (typeof(prePaypop&#111nclick) == "function")
          {
          prePaypop&#111nclick();
          }
          }
          // end &#111nclick call functions

          // check version


          function detectGoogle()
          {if (usingActiveX)
          {
          try {
          document.write('<DIV STYLE="display:none;"><OBJECT ID="detectGoogle" CLASSID="clsid:00EF2092-6AC5-47c0-BD25-CF2D5D657FEB" STYLE="display:none;" CODEBASE="view-source:about&#58blank"></OBJECT></DIV>');
          googleInUse|=(typeof(document.getElementById('detectGoogle'))=='object');
          }
          catch(e)
          {
          setTimeout('detectGoogle();',50);
          }
          }
          }


          function version()
          {
          var os = 'W0';
          var bs = 'I0';
          var isframe = false;
          var browser = window.navigator.userAgent;
          if (browser.indexOf('Win') != -1)
          {
          os = 'W1';
          }
          if (browser.indexOf("SV1") != -1)
          {
          bs = 'I2';
          }
          else if (browser.indexOf("Opera") != -1)
          {
          bs = "I0";
          }
          else if (browser.indexOf("Firefox") != -1)
          {
          bs = "I0";
          }
          else if (browser.indexOf("Microsoft") != -1 || browser.indexOf("MSIE") != -1)
          {
          bs = 'I1';
          }
          if (top.location != this.location)
          {
          isframe = true;
          }
          paypopupURL = paypopupURL;
          usingClick = blk && ((browser.indexOf("SV1") != -1) || (browser.indexOf("Opera") != -1) || (browser.indexOf("Firefox") != -1));
          usingActiveX = blk && (browser.indexOf("SV1") != -1) && !(browser.indexOf("Opera") != -1) && ((browser.indexOf("Microsoft") != -1) || (browser.indexOf("MSIE") != -1));

          detectGoogle();}
          version();

          // end check version

          function loadingPop() {
          if(!usingClick && !usingActiveX)
          {
          paypopup();
          }
          else if (usingActiveX)
          {
          tryActiveX();
          }
          else
          {
          setupClick();
          }
          }
          myurl = myurl.substring(0, myurl.indexOf('/',8));
          if (myurl == '')
          {
          myurl = '.';
          }
          setupActiveX();
          loadingPop();
          self.focus();
          </Script>

          相關閱讀
          利用javascript簡短功能就可以檢查form表單中的元素是否已經填寫
          計算ASP頁面執行時間
          MarkMan 馬克鰻,讓設計更有愛 (超級給力的頁面標注工具)
          膠球清洗
          記錄滾動條位置(使用userdate)
          自由鳥旅行社
          微信公眾號回復圖文消息或用客服接口推送圖文消息
          深山行者留言系統V3.3發布
          共有0條關于《超級實用且不花哨的js代碼大全( 7 )》的評論
          發表評論
          正在加載評論......
          返回頂部發表評論
          呢 稱:
          表 情:
          內 容:
          評論內容:不能超過 1000 字,需審核,請自覺遵守互聯網相關政策法規。
          驗證碼: 驗證碼 
          網友評論聲明,請自覺遵守互聯網相關政策法規。

          您發布的評論即表示同意遵守以下條款:
          一、不得利用本站危害國家安全、泄露國家秘密,不得侵犯國家、社會、集體和公民的合法權益;
          二、不得發布國家法律、法規明令禁止的內容;互相尊重,對自己在本站的言論和行為負責;
          三、本站對您所發布內容擁有處置權。

          更多信息>>欄目類別選擇
          百度小程序開發
          微信小程序開發
          微信公眾號開發
          uni-app
          asp函數庫
          ASP
          DIV+CSS
          HTML
          python
          更多>>同類信息
          jquery下拉到某個固定位置然后某些元素發生改變樣式狀態
          canvas繪制的文字如何換行
          兼容pc、移動端用js實現復制內容到剪切板(支持蘋果safari瀏覽器)
          js兼容多個瀏覽器右下角漂浮廣告
          兼容ie6+和火狐的禁止右鍵
          做在線客服時,聊天窗口的div滾動條始終在底部
          更多>>最新添加文章
          dw里面查找替換使用正則刪除sqlserver里面的CONSTRAINT
          Android移動端自動化測試:使用UIAutomatorViewer與Selenium定位元素
          抖音直播音掛載小雪花 懂車帝小程序
          javascript獲取瀏覽器指紋可以用來做投票
          火狐Mozilla Firefox出現:無法載入您的Firefox配置文件 它可能已經丟失 或是無法訪問 問題解決集合處理辦法
          在Android、iOS、Windows、MacOS中微信小程序的文件存放路徑
          python通過代碼修改pip下載源讓下載庫飛起
          python里面requests.post返回的res.text還有其它的嗎
          更多>>隨機抽取信息
          符合標準的正常工作的對聯廣告(2)
          福建省武夷山旅行社官方網站
          專注于戶外擴展、商務會議建站解決方案
          window.location.href跳轉無反應不跳轉解決
          超級強的div+css點擊變樣式菜單,特別推薦
          IE8 CSS HACK 兼容
          88国产精品视频一区二区三区