View Background Image in Opera/Chrome/IE with a javascript bookmarklet

Create a new book mark (preferably on your bookmarks bar or) wherever you choose within easy access, and then select and paste in all of this code as the URL/address:

javascript:var backup=document.body.onclick;void(document.body.onclick=function(event){var bodyStyle=window.getComputedStyle(document.body,null).getPropertyValue(‘background-image’);var bgStyle=window.getComputedStyle(,null).getPropertyValue(‘background-image’);if(bgStyle!=’none’)\(“?/,”).replace(/”?\)$/,”));else if(bodyStyle!=’none’)\(“?/,”).replace(/”?\)$/,”));document.body.onclick=backup;backup=undefined;});

To view any web page’s background image, first click on the bookmark then click on the background image you wish to view.

It should work, amazingly well, if the page does have a background image!

Got it set up in IE9, Chrome18, Opera11, no probs

These steps are not necessary in Mozilla’s Firefox browser, which already has an in-built “View Background Image” option on its right-click context menu.

But this just saves the hassle of having to copy a URL from Chrome/Opera/IE into Firefox just to view a background image.

Tip of the hat to MyOpera for the tip.


Broken Function: There are some problems with the code below. Identify at least 4 issues.

private void GetCustomers()
System.Text.StringBuilder sBuilder = new System.Text.StringBuilder(“”);
System.Data.SqlClient.SqlDataReader oDR;
String sOutput;
System.Data.SqlClient.SqlConnection oConn;

System.Data.SqlClient.SqlCommand oCmd = new System.Data.SqlClient.SqlCommand(“usp_GetCustomerNames”,oConn);

oCmd.CommandType = CommandType.StoredProcedure;

oDR = oCmd.ExecuteReader(CommandBehavior.CloseConnection);

while (oDR.Read)
sBuilder.Append(oDR(“ForeName”) & “;”);

catch (Exception ex)


return sOutput;



1) System.Data.SqlClient.SqlConnection oConn;
The connection object declared but then is not instantiated with a valid connection string,

for eample oConn.ConnectionString = “Data Source=(local);Database=AdventureWorks;Integrated Security=SSPI”

StringBuilder constructor arguments cannot be empty string

3) return sOutput;

No valid string is assigned to the sOutput variable returned by the GetCustomers() function.
catch (Exception ex)



There is no code written to deal with the exception in the try/catch exception handler.
for example, to display a message to the user, or cancel the exception in order to allow processing to continue uninterruppted.

“The page is trying to close the window” warning message.

Fix: Javascript: How to Close Browser Window [window.close()] Without Warning

There is function window.close() in javascript to close browser window. If we call it from the main browser window (not the one opened with – we get: “The page is trying to close the window” warning message.
This warning message shows up every time one tries to close browser window with window.close() function. It seems impossible to close the most outer main browser window and not to get this message.

But wait… window.close() function implementation is just so simple. It checks window.opener. If “opener” equals empty string it suspects that we talk about parent window (not the one that was opened with…)) and pop-ups warning. And it is easy to work around:
< a href=”javascript:window.opener=’x’;window.close();”>Close< /a>