Ïê½âÇ°¶ËÔÚhtmlÒ³ÃæÖ®¼äͨ±¨²ÎÊýµÄ°ì·¨
ÎÒÃǾ³£Ð´form±íµ¥£¬Ìύʱ£¬¿ÉÒÔ´«µÝ²ÎÊý£¬¼ÙÈçʹÓÃ±íµ¥£¬²¢½«ÆäDZ²ØÆðÀ´£¬Ó¦µ±¿ÉÒÔµ½´ï½á¹û¡£
³ý´ËÖ®Í⣬window.location.hrefºÍwindow.openÒ²¿ÉÒÔµ½´ï½á¹û¡£
1¡¢Í¨¹ýform±íµ¥´«µÝ²ÎÊý
<html> <head> <!--ÍøÕ¾±àÂë¸ñ¾Ö£¬UTF-8 ¹ú¼Ê±àÂ룬GBK»ò gb2312 ÖÐÎıàÂë--> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> <meta name="Keywords" content="¹Ø¼ü´ÊÒ»£¬¹Ø¼ü´Ê¶þ"> <meta name="Description" content="ÍøÕ¾ÃèдÄÚÈÝ"> <meta name="Author" content="Yvette Lau"> <title>Document</title> <!--css js ÎļþµÄÒýÈë--> <!-- <link rel="shortcut icon" href="images/favicon.ico"> --> <link rel="stylesheet" href=""/> <script type = "text/javascript" src = "jquery-1.11.2.min.js"></script> </head> <body> <form name = "frm" method = "get" action = "receive.html" onsubmit = "return foo()" style = "position:relative;"> <input type="hidden" name="hid" value = "" index = "lemon"> <img src = "main_jpg10.png" /> <input type = "submit" style = "position:absolute;left:10px;top:0px;width:120px;height:40px;opacity:0;cursor:pointer;"/> </form> <form name = "frm" method = "get" action = "receive.html" onsubmit = "return foo()" style = "position:relative;"> <input type="hidden" name="hid" value = "" index = "aaa"> <img src = "main_jpg10.png" /> <input type = "submit" style = "position:absolute;left:10px;top:0px;width:120px;height:40px;opacity:0;cursor:pointer;"/> </form> <form name = "frm" method = "get" action = "receive.html" onsubmit = "return foo()" style = "position:relative;"> <input type="hidden" name="hid" value = "" index = "bbb"> <img src = "main_jpg10.png" /> <input type = "submit" style = "position:absolute;left:10px;top:0px;width:120px;height:40px;opacity:0;cursor:pointer;"/> </form> </body> </html> <script> function foo(){ var frm = window.event.srcElement; frm.hid.value = $(frm.hid).attr("index"); return true; } </script>
µã»÷ͼƬʱ£¬ÌøתÖÁreceive.htmlÒ³Ãæ¡£Ò³ÃæµÄurl±ä³É£º
ÎÒÃÇÏëÒª´«µÄ×Ö·û´®ÒѾ´«µÝÁ˹ýÀ´¡£
È»ºóÔÙ¶Ôµ±Ç°µÄurlÍ£Ö¹×Ö·û´®·Ö¸î
window.location.href.split(¡°=¡±)[1]//µÃµ½lemon
ÎÒÃÇÄõ½ÐèÒª´«À´µÄ²ÎÊýÖ®ºó£¬¾Í¿ÉÒÔ°´ÕÕÕâ¸öÍ£Ö¹ÏÂÒ»²½µÄ´¦ÖÃÁË¡£
³ýÁËÉÏÊöͨ¹ý×Ö·û´®·Ö¸îÀ´ÁÔÈ¡url´«µÝµÄ²ÎÊýÍ⣬ÎÒÃÇ»¹¿ÉÒÔͨ¹ýÕýÔòÆ¥ÅäºÍwindow.location.search°ì·¨À´ÁÔÈ¡¡£
2¡¢Í¨¹ýwindow.location.href
±ÈÈçÎÒÃǵã»÷ij¸öÁÐ±í£¬ÐèÒª´«µÝÒ»¸ö×Ö·û´®µ½detail.htmlÒ³Ã棬Ȼºódetail.htmlÒ³Ãæ°´ÕÕ´«À´µÄÖµ£¬Í¨¹ýajax½»»¥Êý¾Ý£¬¼ÓÔØÒ³ÃæµÄÄÚÈÝ¡£
var index = "lemon"; var url = "receive.html?index="+index; $("#more").click(function(){ window.location.href = url; });
µ±Ç°Ò³Ãæ»á±»¸ü»»³Érecieve.htmlµÄÒ³Ã棬ҳÃæµÄurl±äΪ£º
È»ºóÎÒÃÇÔÙÓÃÉÏÃæµÄ°ì·¨ÌáÈ¡±¾ÈËÐèÒªµÄ²ÎÊý
3¡¢Í¨¹ýwindow.location.open
¼ÙÈçÊǵ«Ô¸·¿ªÒ»¸öÐÂÒ³Ã棬¶ø²»ÊǸĶ¯µ±Ç°µÄÒ³Ã棬ÄÇôwindow.location.href¾Í²»ÊÊÓÃÁË£¬´Ëʱ£¬ÎÒÃÇÐèÒª½èÖúÓÚwindow.location.open()À´ÊµÏÖ
¼ò±ã½éÉÜÓÐÒ»ÏÂwindow.open()º¯Êý£¬window.open()ÓÐÈý¸ö²ÎÊý£¬µÚÒ»¸ö²ÎÊýÊÇÒª·¿ªµÄÒ³ÃæµÄurl,µÚ¶þ¸ö²ÎÊýÊÇ´°¿ÚÄ¿±ê£¬µÚÈý¸ö²ÎÊýÊÇÒ»¸öÌض¨×Ö·û´®ÄËÖÁÒ»¸ö±íʾÐÂÒ³Ãæ¿É·ñ´úÌæÔĶÁÆ÷ÀúÊ·¼¯Öе±Ç°¼ÓÔØÒ³ÃæµÄ²¼¶ûÖµ£¬Í¨¹ýÖ»ÐèÒª´«µÝµÚÒ»¸ö²ÎÊý¡£µÚ¶þ¸ö²ÎÊý»¹¿ÉÒÔÊÇ¡±_blank¡±,¡±_self¡±,¡±_parent¡±,¡±_top¡±ÕâÑùµÄ·Ç·²´°¿ÚÃû³Æ£¬¡±_blank¡±·¿ªÐ´°¿Ú,¡±_self¡±ÊµÏֵĽá¹ûͬwindow.location.href.
Á¬ÐøÉÏÃæµÄÀý×Ó£º
<script> var index = "lemon"; var url = "receive.html?index="+index; $("#more").click(function(){ window.open(url) }); </script>
ÕâÑùÔÚµã»÷µÄʱºò£¬¾Í»á·¿ªÒ»¸öÐÂÒ³Ã棬ҳÃæµÄurlµØÖ·ÓëÉÏÃæÀ×ͬ¡£
ÓÉÓÚÔĶÁÆ÷µÄƽ°²ÏÞÖÆ£¬ÓÐЩÔĶÁÆ÷ÔÚµ¯³ö´°¿ÚÅäÖ÷½ÃæÔöÌíÏÞÖÆ£¬´ó¶àÊýÔĶÁÆ÷¶¼ÄÚÖÃÓе¯³ö´°¿ÚµÄÆÁ±Î³ÌÐò£¬Òò´Ë£¬µ¯³ö´°¿ÚÓдó¸Å±»ÆÁ±Î£¬ÔÚµ¯³ö´°¿Ú±»ÆÁ±Îʱ£¬ÐèҪ˼¿¼Á½ÖÖ´ó¸ÅÐÔ£¬Ò»ÖÖÊÇÔĶÁÆ÷ÄÚÖõÄÆÁ±Î³ÌÐò×èÄÓµ¯³ö´°¿Ú£¬ÄÇô window.open()ºÜ´ó¸Å·µ»ØNull£¬´Ëʱ£¬Ö»Òª¼à²âÕâ¸ö·µ»ØµÄÖµ¾Í¿ÉÒԿ϶¨µ¯³ö´°¿Ú¿É·ñ±»ÆÁ±Î¡£
var newWin = window.open(url); if(newWin == null){ alert("µ¯´°±»×èÄÓ"); }
ÁíÒ»ÖÖÊÇÔĶÁÆ÷À©Õ¹»òÆäËû³ÌÐò×èÄӵĵ¯³ö´°¿Ú£¬ÄÇôwindow.open()ƽ³£»áÅ׳öÒ»¸ö´íÎó£¬Òò´Ë£¬ÒªÏñ׼ȷµÄ¼ì²âµ¯³ö´°¿Ú¿É·ñ±»ÆÁ±Î£¬±ØÐèÔÚ¼ì²â·µ»ØÖµµÄͬʱ£¬½«window.open()·â×°ÔÚtry-catch¿éÖУ¬ÉÏÃæµÄÀý×ÓÖпÉÒÔд³ÉÈçÏÂÇéÊÆ£º
<script> var blocked = false; try{ var index = "lemon"; var url = "receive.html?index="+index; $("#more").click(function(){ var newWin = window.open(url); if(newWin == null){ blocked = true; } }); } catch(ex){ block = true; } if(blocked){ alert("µ¯³ö´°¿Ú±»×èÄÓ"); } </script>
ÒÔÉϾÍÊÇÏê½âÇ°¶ËÔÚhtmlÒ³ÃæÖ®¼ä´«µÝ²ÎÊýµÄ°ì·¨µÄ¾ßÌåÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢°Ù·Ö°ÙÔ´ÂëÍøÆäËüÏà¹ØÎÄÕ£¡
¸ÐлÄúµÄÖ§³Ö£¬ÎÒ»á¼ÌÐøŬÁ¦µÄ!
´ò¿ªÖ§¸¶±¦É¨Ò»É¨£¬¼´¿É½øÐÐɨÂë´òÉÍŶ
°Ù·Ö°ÙÔ´ÂëÍø ½¨Òé´òÉÍ1¡«10Ôª£¬ÍÁºÀËæÒ⣬¸ÐлÄúµÄÔĶÁ£¡