如果已在浏览器中打开,则如何将URL打开到同一选项卡

时间:2016-04-19 18:38:44

标签: html jsp browser tabs href

我正面临一些挑战 - 让我们考虑一下我有一个菜单,然后我有3个链接 -

About
Contact Us
FAQs

默认主页是关于菜单项。 现在,当我点击" 联系我们" ,我想在同一浏览器窗口中打开一个新选项卡。如果没有关闭这个,我再次叮叮当当" 联系我们"从第一个标签this time I do not want to open new tab because I have already an open tab for Contact us,我只想导航到之前打开的同一个标签。 如何在jsp。

中处理这种情况

有没有办法做到这一点。请帮帮我。

2 个答案:

答案 0 :(得分:7)

您始终可以在目标中添加名称,以便它始终转到相同的窗口/标签

<a href="somerandomurl.com" target="mywindow">Contact Us<\a>

无法在Internet Explorer上控制此操作。 但是,您可以更改IE的行为方式: -互联网选项 -tabs - 始终在新选项卡中打开弹出窗口 - 打开其他程序中的链接:当前窗口中的新选项卡

target="_blank"将始终确保在新窗口中打开 http://www.w3schools.com/tags/att_a_target.asp

然而,它会使用相同的网址刷新页面

您可以让链接返回一个javascript窗口对象,并且可以随时返回到窗口而无需刷新页面

&#13;
&#13;
var newtab = null;

function openwindow(){
  if (newtab==null) {
    newtab = window.open("www.example.com");
  } else {
    newtab.focus();
  }

}
&#13;
<a onclick="openwindow()">click me</a>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

如果有人刷新父页面,此解决方案将起作用,如果在刷新父页面时该选项卡已打开,它将关闭子选项卡。
使用Javascript:

echo "===> Add webupd8 repository..."  &&      echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main" | tee /etc/apt/sources.list.d/webupd8team-java.list  &&         echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main" | tee -a /etc/apt/sources.list.d/webupd8team-java.list  &&       apt-key adv --keyserver keyserver.ubuntu.com --recv-keys EEA14886  &&   apt-get update  &&      echo "===> Install Java9"  &&   echo debconf shared/accepted-oracle-license-v1-1 select true | debconf-set-selections  &&    echo debconf shared/accepted-oracle-license-v1-1 seen true | debconf-set-selections  &&         DEBIAN_FRONTEND=noninteractive apt-get install -y oracle-java9-installer oracle-java9-set-default --assume-yes
 ---> Running in 45c02c79cbe6
===> Add webupd8 repository...
deb http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main
deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main
Executing: /tmp/tmp.eMJdEX6PMy/gpg.1.sh --keyserver
keyserver.ubuntu.com
--recv-keys
EEA14886
gpg: requesting key EEA14886 from hkp server keyserver.ubuntu.com
gpg: key EEA14886: public key "Launchpad VLC" imported
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)
Hit:1 http://security.ubuntu.com/ubuntu xenial-security InRelease
Hit:2 http://archive.ubuntu.com/ubuntu xenial InRelease
Get:3 http://ppa.launchpad.net/webupd8team/java/ubuntu trusty InRelease [15.5 kB]
Hit:4 http://archive.ubuntu.com/ubuntu xenial-updates InRelease
Hit:5 http://archive.ubuntu.com/ubuntu xenial-backports InRelease
Get:6 http://ppa.launchpad.net/webupd8team/java/ubuntu trusty/main Sources [1,403 B]
Get:7 http://ppa.launchpad.net/webupd8team/java/ubuntu trusty/main amd64 Packages [3,146 B]
Fetched 20.0 kB in 1s (15.6 kB/s)
Reading package lists...
===> Install Java9
Reading package lists...
Building dependency tree...
Reading state information...
The following additional packages will be installed:
  gsfonts gsfonts-x11
Suggested packages:
  binfmt-support visualvm ttf-baekmuk | ttf-unfonts | ttf-unfonts-core
  ttf-kochi-gothic | ttf-sazanami-gothic ttf-kochi-mincho
  | ttf-sazanami-mincho ttf-arphic-uming
The following NEW packages will be installed:
  gsfonts gsfonts-x11 oracle-java9-installer oracle-java9-set-default
0 upgraded, 4 newly installed, 0 to remove and 71 not upgraded.
Need to get 3,417 kB of archives.
After this operation, 5,110 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu xenial/main amd64 gsfonts all 1:8.11+urwcyr1.0.7~pre44-4.2ubuntu1 [3,374 kB]
Get:2 http://ppa.launchpad.net/webupd8team/java/ubuntu trusty/main amd64 oracle-java9-installer amd64 9.0.4-1~webupd8~0 [31.3 kB]
Get:3 http://ppa.launchpad.net/webupd8team/java/ubuntu trusty/main amd64 oracle-java9-set-default amd64 9.0.4-1~webupd8~0 [4,482 B]
Get:4 http://archive.ubuntu.com/ubuntu xenial/universe amd64 gsfonts-x11 all 0.24 [7,314 B]
Preconfiguring packages ...
Fetched 3,417 kB in 1s (2,573 kB/s)
Selecting previously unselected package oracle-java9-installer.
(Reading database ... 66458 files and directories currently installed.)
Preparing to unpack .../oracle-java9-installer_9.0.4-1~webupd8~0_amd64.deb ...
oracle-license-v1-1 license has already been accepted
Unpacking oracle-java9-installer (9.0.4-1~webupd8~0) ...
Processing triggers for hicolor-icon-theme (0.15-0ubuntu1) ...
Processing triggers for shared-mime-info (1.5-2ubuntu0.1) ...
Processing triggers for desktop-file-utils (0.22-1ubuntu5.1) ...
Processing triggers for mime-support (3.59ubuntu1) ...
Setting up oracle-java9-installer (9.0.4-1~webupd8~0) ...
No /var/cache/oracle-jdk9-installer/wgetrc file found.
Creating /var/cache/oracle-jdk9-installer/wgetrc and
using default oracle-java9-installer wgetrc settings for it.
Downloading Oracle Java 9...
--2018-03-24 06:15:33--  http://download.oracle.com/otn-pub/java/jdk/9.0.4+11/c2514751926b4512b076cc82f959763f/jdk-9.0.4_linux-x64_bin.tar.gz
Resolving download.oracle.com (download.oracle.com)... 23.57.201.44
Connecting to download.oracle.com (download.oracle.com)|23.57.201.44|:80... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: https://edelivery.oracle.com/otn-pub/ [following]
--2018-03-24 06:15:33--  https://edelivery.oracle.com/otn-pub/
Resolving edelivery.oracle.com (edelivery.oracle.com)... 104.122.102.128, 2600:140f:9:18c::2d3e, 2600:140f:9:193::2d3e
Connecting to edelivery.oracle.com (edelivery.oracle.com)|104.122.102.128|:443... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: http://download.oracle.com/otn-pub/?AuthParam=1521872253_ffa6f7b8f45863ea275d907281a7a538 [following]
--2018-03-24 06:15:33--  http://download.oracle.com/otn-pub/?AuthParam=1521872253_ffa6f7b8f45863ea275d907281a7a538
Connecting to download.oracle.com (download.oracle.com)|23.57.201.44|:80... connected.
HTTP request sent, awaiting response... 404 Not Found
2018-03-24 06:15:33 ERROR 404: Not Found.

download failed
Oracle JDK 9 is NOT installed.
dpkg: error processing package oracle-java9-installer (--configure):
 subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
 oracle-java9-installer
E: Sub-process /usr/bin/dpkg returned an error code (1)
The command '/bin/sh -c echo "===> Add webupd8 repository..."  &&       echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main" | tee /etc/apt/sources.list.d/webupd8team-java.list  &&         echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main" | tee -a /etc/apt/sources.list.d/webupd8team-java.list  &&       apt-key adv --keyserver keyserver.ubuntu.com --recv-keys EEA14886  &&   apt-get update  &&      echo "===> Install Java9"  &&        echo debconf shared/accepted-oracle-license-v1-1 select true | debconf-set-selections  &&       echo debconf shared/accepted-oracle-license-v1-1 seen true | debconf-set-selections  &&         DEBIAN_FRONTEND=noninteractive apt-get install -y oracle-java9-installer oracle-java9-set-default --assume-yes' returned a non-zero code: 100
You have new mail in /var/mail/root

HTML:

<script>
        var newtab = null;
        window.open('', 'business-list', '').close();
        function openwindow() {
            if (!newtab || newtab.closed) {
                newtab = window.open("/admin/business-list.aspx","business-list");
            } else {
                newtab.focus();
            }

        }
    </script>