Reputation: 13
i have a question about onclick popup. How to make it show only once per unique, because the popup link always opened after i click everywhere on my website.
<script type="text/javascript">
function load() {window.open('http://...','_blank');}
</script>
So, how to make it show only once?
Upvotes: 1
Views: 826
Reputation: 5492
Based on information provided I assume that you are trying to attach the load
handler to one of your target element on click
event and after first click the event handler should not fire.
Hence I can suggest you to use the once
option of the addEventListener()
method:
element.addEventListener('click', load.bind(this), false, false);
Get more info here at MDN.
Upvotes: 1
Reputation: 5546
You could try like this
Store your window state in one variable and re use it when you want to open other URL
<script type="text/javascript">
var popupWin = null;
function load() {
popupWin = window.open('http://...','_blank');
}
function openOtherURL(){
popupWin.location.href = url;
}
</script>
Upvotes: 0
Reputation: 12880
You could try storing the state of your popup in a var :
var popupShown = false;
function load() {
if(!popupShown) window.open('http://...','_blank');
popupShown=true;
}
Upvotes: 2