且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何让Chrome在新标签页中打开多个网站

更新时间:2022-11-15 19:56:25


是否有Chrome设置或扩展程序
,当
在没有用户输入的情况下加载时,它们将在标签页中打开链接?


查看 Chrome扩展文档中的create方法。默认情况下,它会打开一个新标签页,你可以选择指定你想要打开的标签页窗口,并给这个标签页设置一个url。


I'm developing a tool that lets you open multiple pages at once with a shortcut, to be used for things like opening your daily sites or querying multiple search engines for a phrase. In Firefox, Internet Explorer and Opera, assuming you've unblocked pop-ups for the domain, the code works as expected.

Chrome, however, opens the sites in new windows instead of tabs if the links are opened automatically when the page loads. If openAll() is commented out and the button is clicked or a key is pressed, the pages open in tabs. Note it's calling the exact same function.

The best solution I've found (which isn't saying much) is the One Window extension. It works, but you can see the new window open then get sucked back in, and it keeps you from opening new Windows with Ctrl-N, forcing you to drag tabs out to use another Chrome window.

I can understand there not being a programmatic way to change this because it's a browser setting, but as a user of the tool it's annoying to have the sites all open in new windows. Is there a Chrome setting or extension that will open links in tabs when they're loaded without user input? I realize opening a bevy of windows is the very thing browsers aim to stop, but this is one time where I want to allow it.

<input id="openAllBtn" type="button" value="Open all links"> (Or press any key)
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.6.1.min.js"></script>
<script type="text/javascript">
function openAll() {
    window.open('http://yahoo.com/');
    window.location.replace('http://www.bing.com/');
    return false;
}
$(document).ready(function() {
    $(document).bind('keypress', openAll);
    $("#openAllBtn").bind("click", openAll);
    openAll();
});
</script>

Here's a Fiddle of the code: http://jsfiddle.net/sfzjR/

Is there a Chrome setting or extension that will open links in tabs when they're loaded without user input?

Check out the create method in the chrome extension docs. By default it will open a new tab, you can optionally specify the window you want that tab to open in, and give the tab a url.