简体   繁体   中英

How to open popup on page load only if link is available

I found code for open popup on page load, but i cant figure out how to open a popup link on pageload only if Link is added. If link is empty, it does nothing.

I am using my code from here .

Javascript

<SCRIPT TYPE="text/javascript">
<!--
    function popup(mylink, windowname) 
    {
        if (!window.focus)
            return true;
        var href;
        if (typeof (mylink) == 'string')
            href = mylink;
        else
            href = mylink.href;
        window.open(href, windowname, 'width=400,height=200,scrollbars=yes');
        return false;
    }
//-->
</SCRIPT>

HTML

<BODY onLoad="popup('autopopup.html', 'ad')">

IF i understood your question, you need to use a condition before you open the new document.

if (href !== '' && href !== null) {
    window.open(href, windowname, 'width=400,height=200,scrollbars=yes');
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM