如果已在浏览器中打开,如何将 url 打开到同一选项卡 [英] How to open url to the same tab if its already open in browser

查看:49
本文介绍了如果已在浏览器中打开,如何将 url 打开到同一选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am facing some challenge- Lets consider I have a menu and under that I have 3 links-

About
Contact Us
FAQs

默认主页是关于菜单项.现在,当我点击联系我们"时,我想在同一浏览器窗口中打开一个新选项卡.如果我再次点击第一个标签中的联系我们",则无需关闭此选项,这次我不想打开新标签,因为我已经打开了一个用于联系我们的标签,我只想导航到之前打开的那个.如何在jsp中处理这种情况.

By default home page is About menu item. Now when I am clicking on "Contact Us" , I want to open a new tab on same browser window. And without closing this if again I am clinking on "Contact Us" from the first tab, this time I do not want to open new tab because I have already an open tab for Contact us, I just wanted to navigate to the same one which is earlier opened. How to handle this scenario in jsp.

有什么办法可以做到这一点.请帮帮我.

Is there any way to do this. please help me.

推荐答案

你总是可以在目标中添加一个名称,这样它就会总是转到同一个窗口/标签

you can always put a name in the target so it will always go to the same window/tab

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

无法在 Internet Explorer 上进行控制.但是,您可以更改 IE 的行为方式:-互联网选项-标签- 总是在新标签页中打开弹出窗口-在以下位置打开来自其他程序的链接:当前窗口中的新标签

Its not possible to control this on Internet explorer. You can however change how IE behaves: -Internet Options -Tabs -Always open pop-ups in a new tab -Open links from other programs in: A new tab in the current window

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

target="_blank" will always make sure it opens in a new window http://www.w3schools.com/tags/att_a_target.asp

但是它会使用相同的 url 刷新页面

It will however refresh the page with the same url

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

You can have the link return a javascript window object and be able to return to the window anytime you want without refreshing the page

var newtab = null;

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

}

<a onclick="openwindow()">click me</a>

这篇关于如果已在浏览器中打开,如何将 url 打开到同一选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆