• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Setting background color on popup window with javascript?

IronWing

No Lifer
I have the following code that creates a popup window to show image.jpg when the reader clicks on tn_image.jpg. I would like to set the the background color of the popup window.
Code:
<a href="javascript:;" onClick="w = window.open('image.jpg','TpWebWizImage','width=1500,height=1051,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no'); w.resizeTo(1557,1141); w.focus()" style="cursor:hand">
<img src="tn_image.jpg" border="0" width="300" height="210" alt="image.jpg" />

I've tried adding background-color: #00000 and bgcolor:black to the style statement but it gets ignored. Any ideas how to set the background color? Thanks.

Edit: upon further reading it seems that to change the background color of the popup I have to put the image inside a document so I can change the document's background color.
 
Last edited:
First, you are opening a window linking directly to the image. You could open a window to a web page that contains an img tag with the image.

Second, why open a true pop-up window? They make libraries for this kind of thing.
 
The Lightbox and Modal scripts pre-load all the images. I have about a hundred images to show (150MB) so I'd rather not pre-load them, hence the popup script. You're right that I would have to dynamically create a webpage to contain an image. I used to know how to do that but haven't played with it in over a decade. I'll have to review my old scripts and see what I can salvage.
 
What you are doing and what you are asking are two different things.

Your code is just opening another browser window.

But from what you are saying you want, it sounds like you want to popup a modal on the current page that just displays the image, similar to the example Ken provided.
 
What you are doing and what you are asking are two different things.

Your code is just opening another browser window.

But from what you are saying you want, it sounds like you want to popup a modal on the current page that just displays the image, similar to the example Ken provided.
The lightbox Ken provided should work well (Thanks Ken!). I wanted the popup because I wanted readers to have the ability to resize the images. The behavior of the popups is inconsistent across browsers so the lightbox looks like a better bet overall. Ideally the modal would open and then users could choose to make the image fullsize (extending beyond the viewport with scrollbars) but the script is set up to either size the image to the viewport or render it fullsize, but not both. If you have thoughts on how to modify the script to allow resizing the image by the user, that would make it perfect.
 
Back
Top