Reputation: 15
I planed to create a popup to my website . keep on searching i find a code to create a popup new window to my website .
<script type="text/javascript">
document.body.onclick= function(){
window.open('popup creating website', 'poppage', 'toolbars=0, scrollbars=1, location=0, statusbars=0, menubars=0, resizable=1, width=950, height=650, left = 300, top = 50');
}</script>
With the above code i the popup new window is creating for every click . It become a big nuisance to vistor .
Keep on searching the result is nill and zero in stackoverflow i find but the code is not suted to my website . The code i am trying to get is
when the page refresh and first click on website should raise popup .
Can any one help me to get out of my problem..!!
Upvotes: 1
Views: 227
Reputation: 15
From your comments i fouded the correct answer what i expected
-
<script type="text/javascript">
var firstClick = true;
document.body.onclick = function() {
if (firstClick) {
window.open('popup site', 'poppage', 'toolbars=0, scrollbars=1, location=0, statusbars=0, menubars=0, resizable=1, width=950, height=650, left = 300, top = 50');
firstClick = false;
}
}
</script>
<script type="text/javascript">
var firstClick = true;
document.body.onclick = function() {
if (firstClick) {
window.open('popup creating website', 'poppage', 'toolbars=0, scrollbars=1, location=0, statusbars=0, menubars=0, resizable=1, width=950, height=650, left = 300, top = 50');
window.open('popup creating second website', 'poppage2', 'toolbars=0, scrollbars=1, location=0, statusbars=0, menubars=0, resizable=1, width=950, height=650, left = 200, top = 10');
firstClick = false;
}
}
</script>
Upvotes: 0
Reputation: 780724
Use a variable to tell if it's the first click:
var firstClick = true;
document.body.onclick = function() {
if (firstClick) {
window.open('popup creating website', 'poppage', 'toolbars=0, scrollbars=1, location=0, statusbars=0, menubars=0, resizable=1, width=950, height=650, left = 300, top = 50');
window.open('popup creating second website', 'poppage2', 'toolbars=0, scrollbars=1, location=0, statusbars=0, menubars=0, resizable=1, width=950, height=650, left = 200, top = 10');
firstClick = false;
}
}
Upvotes: 0
Reputation: 69276
Looks like you want to open a popup only on the first click. Just use addEventListener
and removeEventListener
to get rid of it after the first click.
Here's the working code:
function createPopup() {
window.open('popup creating website', 'poppage', 'toolbars=0, scrollbars=1, location=0, statusbars=0, menubars=0, resizable=1, width=950, height=650, left = 300, top = 50');
document.body.removeEventListener('click', createPopup);
}
document.body.addEventListener('click', createPopup);
Upvotes: 2
Reputation: 449
To produce a popup,you need to use Javascript,for example:
<script>
function myFunction() {
alert("10/63");
}
function a2() {
alert("13/10");
}
function a3() {
alert("37/30");
}
function a4() {
alert("4/21");
}
</script>
<p>Click the button.</p>
<button onclick="myFunction()">Example 1 Answer</button>
<br>
<button onclick="a2()">Example 2 Answer</button>
<br>
<button onclick="a3()">Example 3 Answer</button>
<br>
<button onclick="a4()">Example 4 Answer</button>
Upvotes: 0