Allow option for “Open Link in New Tab” in [remove

2019-08-22 10:10发布

问题:

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" Many thanks.

          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") . "\">";
      }

Okay, not sure why this was deleted by Tim Post who is a moderator, it was meant to be a further explanation of my problem... Anyway, I will repost as I don't think I've broken any guidelines, the link to the pic is just a further explanation of my issue too.

(Oh god can you tell I'm a newbie here? I can't work the comment thingy out, lost what I typed at least 5 times so far... Anyway this is what I was trying to write to Alex... )

Hi Alex, thank you for your time, I guess I didn't explain my issue properly... The Single File Photo Gallery script does already exclusively open 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.

I'll try to post a pic of what I mean (if it works)

Ok... pic doesn't work... so here's the link:

http://i.stack.imgur.com/1UFaM.jpg

回答1:

You can not force the browser to open in exclusively a tab or window, best you can do is with _blank which will be a new window or tab depending on the browser and its settings.

Best thing you could do is do a oncontextmenu event, make your own menu, and your own button which calls window.open(url, '_blank'), however, replacing user's context menus is very annoying and often disabled.



回答2:

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.