• 获取script的链接参数并执行


    1 <script type="text/javascript" src="http://www.tuiguang.netetao.com/tuiguang2.js?wid=1020&col=white" id="netetao" onload="etao();"></script>

    这 是要插入到<body></body>之间的,不是在<head></head>之间。并且 script的id一定要写到后面。一开始我是直接写在src的前面的,从某个我写的结构少的网站上没问题。可是后来我放到另一个有些大的还有很多插件的 网站上,没有反应。看了看源代码,根本就没有id=""这一项。调整了位置才成功。

    notIe = -[1,];if(-[1,]){ }else{}这是我从网上找的一份极其简易的判断标准浏览器与ie的方法。据说是一个俄罗斯的毛洋鬼子发现的,原理是ie的bug.

     1 notIe = -[1,]; 
     2 if(-[1,]){ 
     3 // 标准浏览器代码 
     4 function etao(paramName)
     5 {   
     6     var reg = new RegExp("(^|/?|&)"+ paramName+"=([^&]*)(/s|&|$)", "i");
     7   
     8     if (reg.test(netetao.src)) //test为script ID 
     9         return RegExp.$2; 
    10     else
    11         return addDiv(); 
    12 }
    13 function addDiv(){
    14         //创建一个div
    15         var div = document.createElement('div');
    16         //设置div的属性
    17         div.innerHTML = "<iframe src='http://www.tuiguang.netetao.com/adcode2.php' frameborder='0' scrolling='no' width='100%' height='100%'></iframe>"; //设置显示的数据,可以是标签.
    18         div.style.width = etao('wid')+"px";//设置css样
    19         div.style.height = etao('wid')/3.5 +"px";
    20         div.style.background = etao('col');//设置css样式
    21         div.style.margin = "0 auto";//设置css样式
    22         var bo = document.body;//获取body对象.
    23         //动态插入到body中
    24         bo.insertBefore(div,bo.lastChild);
    25     }
    26 }else{ 
    27 // IE Only的代码 
    28 var s=document.getElementById("netetao").src;
    29 
    30 function getParameter(str,_parameter)
    31 {
    32     
    33     var sValue=str.match(new RegExp("[?&]"+_parameter+"=([^&]*)(&?)","i"));
    34     if(sValue?sValue[1]:sValue==null)
    35        return sValue?sValue[1]:sValue;
    36 }
    37 var wid =getParameter(s,"wid");
    38 var col =getParameter(s,"col");
    39 
    40 document.write("<div id='yitao'><iframe  src='http://www.tuiguang.netetao.com/adcode2.php' frameborder='0' scrolling='no' width='100%' height='100%'></iframe></div>");
    41 document.getElementById("yitao").style.width = wid +"px";
    42 document.getElementById("yitao").style.height = wid/3.5 +"px";
    43 document.getElementById("yitao").style.background = col;
    44 document.getElementById("yitao").style.margin = "0 auto";
    45 
    46 
    47 }

    上面ifrme的src可以改成.html

    下面是adcode2.php所调用的adcode2.html内容。

     1 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
     2 
     3 {literal}
     4 <style type="text/css">
     5 .shop-list {width:97%;_width:100%;height:80%;padding:20px 12px;list-style-type:none;border:3px solid #FF9900;display:inline-block;*display:inline;position:relative;font-size:12px;margin:0;}
     6 .shop-list li { float: left;padding:0 9px;width:18%;height:100%;}
     7 .item {text-align: left;}
     8 .desc {width:100%;height:13%;_height:20%;line-height:17px;_line-height: 18px;overflow: hidden;padding: 5px 2px;position:relative;}
     9 .desc a { text-decoration:none;color:#333;}
    10 .desc a:hover {color:#FF9900; text-decoration:underline;}
    11 .pic {width:100%;text-align: center;}
    12 .pic a{display: table-cell;vertical-align: middle;}
    13 .pic a img {vertical-align: middle;border: 1px solid #CCCCCC;}
    14 .grid_a {position:absolute;right:0;bottom:0;display:block;width:auto;height:20px;_float:right;text-align:center;padding:0 5px;line-height:20px;color:#fff;background:#FF9900; text-decoration:none;}
    15 .xiaobao {width:14px;height:16px;position:absolute;bottom:0;right:0;z-index:99;background:url(./templates/member/images/xtmall.gif) no-repeat 0 -309px;}
    16 .tmall {width:23px;height:18px;position:absolute;bottom:0;right:18px;z-index:99;background:url(./templates/member/images/tm.gif) no-repeat 0 0;}
    17   </style>
    18 <script>
    19 $(document).ready(function() {
    20     var shopwid = $(".shop-list").width();
    21     var listwid = $(".shop-list li").width();
    22     var picwid = $(".pic").width();
    23     var pichei = $(".pic").height();
    24     var listwid = (shopwid-120)/5;
    25     var picwid = listwid-2;
    26     return $(".pic a img").width(listwid+4).height(listwid-2),$(".desc").width(listwid+4);
    27 });                
    28 function getHttpRequest(){
    29  var A=null; 
    30  try { 
    31  A=new ActiveXObject("Msxml2.XMLHTTP");
    32  } 
    33  catch(e) { 
    34  try { 
    35  A=new ActiveXObject("Microsoft.XMLHTTP");
    36  } 
    37  catch(oc) { 
    38  A=null;
    39  } 
    40  } 
    41 
    42  if ( !A && typeof XMLHttpRequest != "undefined" ) { 
    43  A=new XMLHttpRequest();
    44  } 
    45  return A;
    46 } 
    47 
    48 function RegAjax(s){
    49     if (s!=""){
    50         var url = "addclick.php";    
    51         var Post = "id="+escape(s);         
    52         if (Post){
    53           var ajax = getHttpRequest();
    54           ajax.open("POST", url, false); 
    55           ajax.setRequestHeader("CONTENT-TYPE","application/x-www-form-urlencoded; charset=utf-8"); 
    56           ajax.send(Post);
    57         }
    58     }
    59 }
    60 
    61 function addclick(str){
    62     RegAjax(str);
    63     return true;
    64 } 
    65 </script>
    66 {/literal}
    67 <ul class="shop-list">
    68   {section name=list loop=$code}
    69   <li>
    70     <div class="item">
    71       <div class="pic"> <a href="{$code[list].AD_Url}" target="_blank"  onclick="javascript:addclick({$code[list].ID});"> <img src="./{$code[list].AD}"> </a> </div>
    72       <div class="desc"> <a  class="permalink" href="{$code[list].AD_Url}" target="_blank"  onclick="javascript:addclick({$code[list].ID});"> {$code[list].AdName} </a><i class="xiaobao"></i>{if $code[list].tianmao==2}<i class="tmall"></i>{/if} </div>
    73     </div>
    74   </li>
    75   {/section} <a class="grid_a" href="http://www.tuiguang.netetao.com" target="_blank">Ò×ÌÔÍøÂçÍƹã</a>
    76 </ul>
  • 相关阅读:
    UOJ425【集训队作业2018】strings【分块,常数优化】
    UOJ444【集训队作业2018】二分图【构造,结论】
    各种类型转换为字符串类型(ToString())
    ADO.net数据绑定
    关于扫雷游戏学习笔记(二)
    关于扫雷游戏学习笔记(一)
    Luogu P2864 [USACO06JAN]树林The Grove(bfs)
    Luogu P1712 [NOI2016]区间(线段树)
    Luogu P2051 [AHOI2009]中国象棋(dp)
    Luogu P2577 [ZJOI2005]午餐(dp)
  • 原文地址:https://www.cnblogs.com/Truke/p/2954033.html
Copyright © 2020-2023  润新知