仅在使用javascript和html的浏览器中切换相同的两个选项卡 [英] Switching between the same two tabs only in a browser using javascript and html

查看:143
本文介绍了仅在使用javascript和html的浏览器中切换相同的两个选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对要做什么的想法是
当我在Internet Explorer浏览器的一个选项卡上打开一个网站并单击一个链接时,它应该在具有pdf页面init的同一浏览器中打开一个新选项卡。 .. pdf页面有很多链接,如果你尝试点击它们中的任何一个,他们应该把你带回到那个你设法午餐打开pdf的旧标签,并且只在这两个标签之间切换
I希望这个想法很清楚..我试图用html和javascript来做到这一点...这是我写的,但我仍然在这里错过了很多。预先感谢您提供的任何帮助

My idea of what am trying to do is When I open a website on one tab of an internet explorer broweser and click on a link it should open a new tab in the same browser with a pdf page init ... the pdf page has a lot of links which if u try clicking on any of them they should take you back to the old tab where u managed to lunch open the pdf from and keep switching between those two tabs only I hope the idea is clear .. am trying to do this using html and javascript ... this what I wrote but am still missing a lot here. Thanks in advance for any help provided

这里的这一块在另一个窗口中另一个瞬间

this piece here lunches another instant in another window

<html>
<head>
<script>
function son()
{

 myWindow=window.open('','','width=500,height=500');
 myWindow.document.write(" SON !");
 myWindow.focus();
 myWindow.opener.document.write("<p> DAD !</p>");
}
</script>
</head>
<body>

<input type="button" value="Open " onclick="son()" />

</body>
</html>

这个文件是我内置pdf文件的地方。

This file is where I have the pdf file built in.

<object data="Test.pdf" type="application/pdf" width="100%" height="100%">

<p>It appears you don't have a PDF plugin for this browser.
you can <a href="Test.pdf">click here to
download the PDF file.</a></p>

</object>

再次感谢

thanks again

推荐答案

在过去,您可以使用窗口的 focus 方法将窗口/选项卡放到前景中。然而,滥用(主要以广告商的弹出窗口形式)导致浏览器限制或禁用该功能。

In the old days, you could use a window's focus method to bring a window/tab into the foreground. However, abuse (mostly in the form of advertisers' popup windows) has resulted in browsers restricting or disabling that functionality.

如果我们忽略PDF部分,从概念上讲,这是一个非常简单的要求。首先,打开一个窗口并保留其引用:

If we ignore the PDF part, conceptually, this is a very simple request. First, open a window and hold on to its reference:

var pop = window.open('page.html'); // opens in new tab on most browsers

在辅助页面中,切换回原来很简单:

In the secondary page, switching back to the original was simple:

window.opener.focus(); // no longer works in most modern browsers

然后从第一页开始切回: p>

And from the first page, to switch back:

pop.focus();  // might work

我的测试,我无法让IE 9或Chrome 21切换回开启器选项卡。在Chrome中,我可以打开第二个页面,手动切换回原始选项卡,然后调用 pop.focus()确实将第二个选项卡放回焦点。 (IE什么都没做)。我可以通过从辅助页面调用 window.opener.alert('...'); 来强制Chrome返回到开始页面,但这是一个丑陋的黑客。

In my test, I couldn't get IE 9 or Chrome 21 to switch back to the opener tab. In Chrome, I could open the second page, manually switch back to the original tab, and calling pop.focus() did bring the second tab back in focus. (IE did nothing.) I was able to force Chrome back to the opening page by calling window.opener.alert('...'); from the secondary page, but that's an ugly hack.

因此,看起来您无法将其取消,至少不可靠。

So it looks like you won't be able to pull this off, at least not reliably.

我不确定你想要完成什么(TOC?),但你有没有想过打开两个窗口?打开一个包含屏幕左侧的链接,另一半打开PDF。

I'm not sure exactly what you're trying to accomplish (a TOC?), but have you thought about opening two windows? Open one with your links that covers the left-hand side of the screen, and another on the other half with the PDF.

这篇关于仅在使用javascript和html的浏览器中切换相同的两个选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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