Jump to content

Allow option for “Open Link in New Tab” in javascript:window.open


Recommended Posts

Hi, I'm using Single File Photo Gallery and want to make one mod to the script...

 

Currently the images open in a new pop up window when left-clicked. If you right click on the image thumb it allows the option for "Open Link" but not "Open Link in New Window" or (most importantly for what I want to achieve) "Open Link in New Tab".

 

I've done quite a bit of googling, but since I'm not proficient in php (sort of learn-as-I-go) the few things I've found don't seem to work.

 

I've narrowed the part of the code down to the below, and hoping someone can have a look and let me know what to change it to to allow the right-click option to "Open Link in New Tab".

 

I'm pretty sure this is the part of the code responsible:

 

          if (USE_JAVA and IMAGE_IN_NEW_WINDOW)
          {
            echo "<a href=\"javascript:void(null)\" onClick=\"javascript:window.open('" . sfpg_url(GALLERY, $images[$item], "", "imageform") . "', '', 'toolbar=no, menubar=no, location=no, scrollbars=yes, resizable=yes');\">";
          }
          else
          {
            echo "<a" . (IMAGE_IN_NEW_WINDOW ? " target=\"_blank\"" : "") . " href=\"" . sfpg_url(GALLERY, $images[$item], PAGE, "imageform") . "\">";
          }

 

Now, I know a lot of posts out there ask how to ake something open by default in a new tab to which the answer is you can't - you can only do new window and user will decide on tab/window, this is not my issue... so just to explain further, the Single File Photo Gallery script already exclusively opens an image in my gallery in a new popup window (see javascript:window.open in the code I posted above).

 

This is ok but not ideal for how I want to use my gallery pages.

 

Ideally I want the OPTION to open link in new tab. It's ok for the photos to open in a new window as they do currently as long as you CAN open in a new tab if you so choose.

 

Hmm... I still don't think I'm being clear.. You know on a link, if you right click the standard options are (from top to bottom) "Open" "Open in New Tab" "Open in New Window" etc... Well, currently the options for new tab and new window are greyed out.

 

Here's a pic showing exactly what I mean:

 

1UFaM.jpg

 

All help will be greatly appreciated!!!

I've managed to work it out...

 

I deleted this line of code:

          {
            echo "<a href=\"javascript:window.open('" . sfpg_url(GALLERY, $images[$item], "", "imageform") . "', '', 'toolbar=no, menubar=no, location=no, scrollbars=yes, resizable=yes');\">";
          }
          else

To be left with just this:

          if (USE_JAVA and IMAGE_IN_NEW_WINDOW)
          {
            echo "<a" . (IMAGE_IN_NEW_WINDOW ? " target=\"_blank\"" : "") . " href=\"" . sfpg_url(GALLERY, $images[$item], PAGE, "imageform") . "\">";
          }

And it still automatically opens the image in the new window, the only thing is that it keeps the toolbar/menubar/location/etc in the new window, but it does also allow the option to left click and open in new tab! So it might not be as pretty and neat when left clicked, but at least it's got full functionality on the right click! That's good enough for what I want in any case.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.