I have two scripts for popup windows. In all cases the arguments for the second script is controlling both. How do I fix this?
<script>
function firstPopup(url) {
popupWindow = Window.open(url,'popUpWindow','height=300,width=300,left=200,top=200,resizable=yes,scrollbars=no,toolbar=no,menubar=no,location=no,directories=no,status=yes')
}
</script>
<a href="JavaScript:newPopup('bitcoin.cfm')" style="color:black">Here.<a href="JavaScript:newPopup('contactpri.cfm')" style="color:black"></a></script>
<a href="JavaScript:newPopup('bitcoin.cfm')" style="color:black">Here.<a href="JavaScript:newPopup('contactpri.cfm')" style="color:black"></a>
`
Text and other stuff here.
<script>
function newPopup(url) {
popupWindow = window.open(url,'popUpWindow','height=700,width=800,left=10,top=10,resizable=no,scrollbars=no,toolbar=no,menubar=no,location=no,directories=no,status=yes')}
</script>
<B>If you want to Contact US <a href="JavaScript:newPopup('contact.cfm')" style="color:#062689;">click here.</a></B>`
Both scripts do work. It is just that the second height and width are overwriting the first argument.
What do I need to change to make them used their own arguments? I have no idea have to differentiate the scripts to make this work
2
Answers
Spelling mistake in the Window.open? And using the same name popUpWindow will have the second script act on the same window
I suggest you use delegation and an event listener on the closest static container of the links
From your question it is pretty clear that you have a global variable called
popupWindow
which you set when those functions are being called. Since you use a single variable for both windows, when you assign it to a window, its previous reference will be forgotten, as a variable may have a single value at a time.So, to fix your issue, make sure that you return the opened windows, like:
and
and then you can have an object for your popups:
if you want to open them together. If you do not want to open them together, then you may initialize your object with
undefined
for both fields and override that value when you open a popup.