I have a friefox sidebar extension. If its opened by clicking on the toolbar icon I load it with a webpage ( that I have authored ). Now, if the user clicks on the link on the webpage ( thats loaded into the sidebar ) I want the linked webpage to open up in a new tab of the main window. I tried with this in my webpage markup:
<a target="_content" href="http://www.google.com">Google</a>
But the link opens up in the tab that has focus and not in a new tab.
Please help.
Thanks.
If you use target="_blank" instead, FF (version 3) should open a new tab for it. Haven't tried it from a sidebar, but it's worth giving a shot.
Actually, there is no way to load a webpage ( whose link was in another webpage loaded into the sidebar extension ) onto a new tab in the browser. The only way is to use javascript. That has to execute under privileged conditions ( meaning as part of an extension ) like below:
gBrowser.addTab("http://www.google.com/");
EDIT:
The above technique of adding a browser tab did not work in this case. According to this article code running in the sidebar does not have access to the main window. So first up I got access to the browser window before using gBrowser. Here is the code taken from the website that I used and works properly:
var mainWindow = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIWebNavigation)
.QueryInterface(Components.interfaces.nsIDocShellTreeItem)
.rootTreeItem
.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIDOMWindow);
After I got access to the browser window I accessed gBrowser through the getBrowser function like below:
mainWindow.getBrowser().addTab("http://www.google.com/");
The opens up a new tab in the main window browser.
Google
This is more dependent on the browser that is being used. Firefox and Opera, and I'm sure the newest IE, display "new windows" as a new tab unless otherwise specified by user preference.
Related
I have a series of links, which I want to open in a new window. Once a window is open and a new link is clicked it should reload the window with a new url.
It works fine by providing a specified target (name) to window.open for a series of websites, but somehow after the google search page has been opened it opens up another window.
When I click Open w3school and then Open React the behaviour is as intended. If I click Open google search and then another link it pops up in a new window.
Steps to recreate:
Click Open w3school opens a new window (intended)
Click Open React reloads the page in the opened window (intended)
Click Open google search reloads the page in the opened window (intended)
Click Open w3school opens a new window (not intended)
The code below illustrates the issue.
Does anyone have an explanation of this behaviour?
<html>
<body>
<p>Click the button to open a new browser window.</p>
<button onclick="openW3school()">Open w3school</button>
<button onclick="openGoogleSearch()">Open google search</button>
<button onclick="openReact()">Open React</button>
<script>
function openW3school() {
window.open("https://www.w3schools.com", "mywindow", "popup");
}
function openGoogleSearch() {
window.open("https://www.google.com/search?q=javascript", "mywindow", "popup");
}
function openReact() {
window.open("https://reactjs.org/", "mywindow", "popup");
}
</script>
</body>
</html>
Most probably it is due the fact that the Google search results page is sent with
cross-origin-opener-policy: same-origin-allow-popups; report-to="gws"
HTTP header (while the other two pages in your sample are not), what presumably tells browser "block ties with openers if they were on different domain (origin)".
According to Cross-Origin-Opener-Policy MDN page it should have the effect you describe for Google Chrome:
If a cross-origin document with COOP is opened in a new window, the opening document will not have a reference to it, and the window.opener property of the new window will be null.
It is strange that Firefox does not seem to respect that, although it is presented as compliant there.
One possible explanation would be that some script in the opened page changes its name (window.name).
You can verify / deny that if you check window.name of the "stray / detached" popup window in the console; if it will not be mywindow then you know the cause.
You may also check window.opener - if it is null, then it could indicate that given page deliberately broke ties with your page that created the popup.
I am trying to open a URL in a new window.
The URL is opened in a new window but without any Menu and navigation controls.
JSFiddle: https://jsfiddle.net/Sahil_Gupta/nfuehqv1/2/
I am using JAVA and ZK in backend and using Script to run the code as:
Script jsScriptInitializer = new Script();
String js = "window.open('https://www.google.com', '_blank', 'location=no,scrollbars=yes,toolbar=yes,menubar=yes,resizable=yes');";
jsScriptInitializer.setContent(js);
jsScriptInitializer.setDefer(true);
jsScriptInitializer.setParent(event.getTarget().getParent().getParent());
I need all the navigation and menu controls as usual when I open a URL in another window.
How can I achieve this ?
Your code will work as desired in browsers other than Chrome. There has been an ongoing bug in Chrome which has turned into a feature request. You can read about it at: https://bugs.chromium.org/p/chromium/issues/detail?id=82522
As of Jan 2022, there is still no way to open a Seperate window with the standard toolbars. However, if you can accept the new window being in the form of a tab rather than a separate window, simply eliminating the third argument will open as a fully featured tab.
// open a new tab
window.open('https://www.google.com', '_blank');
Chromium-based browser has the apps page at chrome://apps
There are some apps that I have installed into it. Is it able to launch one of them from JavaScript somewhat just like opening file selecting box?
I can open chrome://apps by setting this URL in to a link, but how about a single app?
Copied from: Open Chrome in a new window (Chrome app)
Sadly, there's no way to do that I know of.
Using window.open in an app's context is a bit of a hack, but results in the URL being open in the user's default browser (not necessarily Chrome). There's no control as to how the browser chooses to open it.
There's a Chrome App-specific API that was created specifically with "open a page in Chrome" in mind, chrome.browser. However, it still doesn't provide an option to open in a new window.
The closest you can get is to create your own "browser": an app window with an in it. Then you have full control over the presentation, but it's not integrated with Chrome's profile and may require additional work to implement things like dialogs and browser controls. See the Browser sample app and documentation.
You may need the app id which you can then append to the URL. I am not entirely sure how you would find but if you go to the apps page on chrome, drag the icon of the app to the search bar in the browser, you should get the full link.
For instance, I dragged the Google Slides Icon onto the search bar and it gave me this url chrome-extension://aapocclcgogkmnckokdopfmhonfmgoek/main.html. So, you may give it a shot! Try to open the chrome apps page, then drag the app you want to open in new tab onto the search bar.
Hence, using Javascript:
window.open("chrome-extension://aapocclcgogkmnckokdopfmhonfmgoek/main.html", "_blank");
Opens Google Slides App in a new tab.
I am having a Proposal Builder Custom Formula(TEXT) using hyperlink on opportunity. When i click that i am trying to open a VF page in new window.
Hi, i need help on this salesforce task plzz.
My requirement is..
I opened Opportunity In IE and when i click Proposal Builder link on Opp, then that VF page should open in CHROME.
Any Suggestions or ideas plzzz..
Here is the Formula field i created:
HYPERLINK("https://mysalesforceorg.com/apex/cpq?opportunity_id="& Id &""e_id="& Id &"&Session_id="&$Api.Session_ID,"Proposal Builder","_blank")
CPQ is the VF Page to be opened when clicked.
Thankyou...
There is no way to force a browser to pass a URL to a different browser. It would be possible to create shortcuts on your desktop to open certain bookmarks in a specific browser, but what you are asking for is not possible. Once you're operating in a browser, it's going to handle any links/redirects/actions within itself (whether that be in the current tab, in a new tab, or in a new window).
With that said, there are certain extensions for Chrome that would allow an end user to render a page using an IE tab within Chrome...but there's no way for you as the developer to guarantee your users are going to do that.
How do I open a link in a new tab in the extension HTML.
E.g.
clicks on icon
sees Google chrome window which has the window.html
inside there are two links, one link to open a link in a new tab, other in the original tab.
I used window.location, doesn't work like that.
If the page is indeed in a google chrome extension, you can force the browser to open the page in a new tab using javascript (which you know is enabled sine you are a google chrome extension).
chrome.tabs.create({url:"http://somewhere", selected:true});
Your extension will need the tabs permission.
See: http://code.google.com/chrome/extensions/tabs.html
I don't know why this question has two upvotes, but anyway you can try using the target attribute for anchor elements.
<a target="_blank" src="http://myFancyUrl">This is a link to a new tab</a>
However, it won't open in a new tab unless the user has the navigator configured that way (usually does).