|
优点:兼容性很好,而且俺觉得不应该有什么拦截工具可以拦截下来 优点:代码非常短 缺点:必须在页面点击后才会弹出
demo:
运行代码框
<head> <style> #link001 img { border-style:none; } </style> <script> function cancelOpenNew(){ if(!window.event){setTimeout(cancelOpenNewA,1000);return;} var obj=window.event.srcElement; if(!obj)return; if(!obj.tagName)return; if(String(obj.tagName).match(/input|select|option|textarea/i))return; setTimeout(cancelOpenNewA,1000); }
function cancelOpenNewA(){document.body.appendChild(document.getElementById('MainDiv001'));} </script> </head> <body> <a href="http://www.blueidea.com" target="_blank" onclick="cancelOpenNew();" id="link001" style="color:black; text-decoration:none; cursor:default; display:block;" hidefocus="true"> <div id="MainDiv001">
<!-- This is a comment --> This is a test. <br> I try to put something here.<br> <input /> <br> <div > This is a div. </div> <ol> <li><img src="http://www.blueidea.com/articleimg/bbsimg/closedb.gif"/> And this</li> <li><img src="http://www.blueidea.com/articleimg/bbsimg/closed.gif"/> is a list</li> </ol>
<form> This is a Form. <input /><input type="checkbox" /> <input type="radio" name="hutia" value="1" /><input type="radio" name="hutia" value="0" /> <select><option>This is a select</option> <option>This is a select</option> </select> <textarea> And here is a textarea</textarea> <input type="button" value="button" /> <input type="submit" value="submit" /> <input type="reset" value="reset" /> </form>
<iframe src="http://www.blueidea.com"></iframe> <!-- This is another comment -->
</div> </a> </body>
说明:
1.为了保证页面中的 img 不会出现丑陋的边框
<style> #link001 img { border-style:none; } </style>
2.保证窗口只弹出一次
<script> function cancelOpenNew(){ if(!window.event){setTimeout(cancelOpenNewA,1000);return;} var obj=window.event.srcElement; if(!obj)return; if(!obj.tagName)return; if(String(obj.tagName).match(/input|select|option|textarea/i))return; setTimeout(cancelOpenNewA,1000); }
function cancelOpenNewA(){document.body.appendChild(document.getElementById('MainDiv001'));} </script>
3.这个结构是弹窗的根本---其实只不过是个 target="_blank" 的链接而已,拦截程序要是连这个都要拦,俺也无话可说
<body> <a href="http://www.blueidea.com" target="_blank" onclick="cancelOpenNew();" id="link001" style="color:black; text-decoration:none; cursor:default; display:block;" hidefocus="true"> <div id="MainDiv001">
4.千万不要忘记在页面结束的地方加上:
</div> </a> </body> (出处:源码网)
|