Topic: Open Gallery in New Window

I feel dumb asking this question as the answer should be obvious to me but I haven't been able to figured it out. 

I would like to have the Galleries shown on the Gallery index page open in a new browser window. 

I'm trying to avoid making the user hit the back button do get back to the main Gallery page.

Thanks for any assistance,

Dwayne

Re: Open Gallery in New Window

Not such a dumb question at all. You could hack the php code so that it adds a "target="_blank" attribute to the link but I think a better approach would be to use javascript to add the attribute.

Here is a suggestion for some javascript to put in the head of the svmanager/index.php file.

<script type="text/javascript">
    //<![CDATA[;
    function setTarget()
    {
      var allTables = document.getElementsByTagName("table");
      for (var i=0; i<allTables.length; i++)
      {
        if (allTables[i].className == "svlinks")
        {
          var linkTable = allTables[i];
          break;
        }
      }
      var galleryLinks = linkTable.getElementsByTagName("a");
      for (var i=0; i<galleryLinks.length; i++)
      {
        galleryLinks[i].target = "_blank";
      }
    }
    window.onload = setTarget;
    //]]>
</script>

It could be more elegant no doubt but I've tried to keep it simple. It just looks for the (first) table with the class "svlinks" and sets the target attribute of all the links inside the table. I'm assuming that you are using the default table layout for the page not the optional div layout.

You could also set the target attribute to a window name instead of _blank if you want all your galleries to open in the same window:

galleryLinks[i].target = "mywindow";

jack

Last edited by jack (2009-09-11 17:24:02)

Jack Hardie
SimpleViewer Support Team.

Re: Open Gallery in New Window

Thank you Jack that is exactly what I was looking for and it worked like a charm! big_smile

Re: Open Gallery in New Window

This doesn't work for me...is there another way of making this happen?

Re: Open Gallery in New Window

I don't know if this was the reason that it didn't work for you but the code sample was badly scrambled during the recent update of the forum software. I've edited the previous post so that it looks like it should.

jack

Jack Hardie
SimpleViewer Support Team.