简体   繁体   中英

How do I get a JavaScript popup to come without clicking link?

I am using some pre-written JavaScript from polldaddy.

They have a JavaScript option which, when you click on the link, the survey pops up as an overlay to my site.

However, I would like when people come to the site, the overlay comes up on its own without needing to click on the link.

Here is the JavaScript:

<script language="javascript" type="text/javascript">
var PDF_surveyID = 'F1B4CE39FE1ECE86';
 var PDF_openText = 'View Survey';
</script>
<script type="text/javascript" language="javascript" src="http://www.polldaddy.com/s.js"></script>
<noscript><a href="http://surveys.polldaddy.com/s/F1B4CE39FE1ECE86/">View Survey</a></noscript>

If you look at the script you're including, you'll see it does this:

document.write('<a href="javascript:PDF_launch(\''+ PDF_surveyID +'\');">'+ PDF_openText +'</a>');

to put the link into the page. What you'll want to do, then, is call PDF_launch when the page loads.

Looking at http://www.polldaddy.com/s.js , the link is written is in the following statement:

document.write('<a href="javascript:PDF_launch(\''+ PDF_surveyID +'\');">'+ PDF_openText +'</a>');

So when you click on the link, it's calling

PDF_launch(PDF_surveyID);

What you'll want to do is call this yourself when the page loads. For example:

<body onload="PDF_launch(PDF_surveyID)">

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