鏈接執(zhí)行js時(shí)注意target必須是_self或者_(dá)top

即: <a href="javscript:someFun()">text</a>
需要特別注意這個(gè)A標(biāo)簽的target必須是_self或者_(dá)top,否則會(huì)新開一個(gè)窗口執(zhí)行js,導(dǎo)致不能執(zhí)行,解決問(wèn)題的一個(gè)簡(jiǎn)單辦法是在文檔結(jié)束時(shí)執(zhí)行下面的js函數(shù)。

<script language="javascript">
function setJsLinksTarget()
{
    var links = document.links;
    for(var i=0;i<links.length;i++){
        if(links[i].href.toLowerCase().indexOf('javascript:') > -1){
            links[i].target = '_self';
        }
    }
}
setJsLinksTarget();
</script>

 

發(fā)表評(píng)論

(required)

This site uses Akismet to reduce spam. Learn how your comment data is processed.