This question already has answers here:
open url in new tab or reuse existing one whenever possible
(2 answers)
Closed 7 years ago.
I have strange functionality requirement. There are two websites which has link of each other. Clicking the link opens other website in a new tab.
However, when the other website is already open in a tab, all i want on button click is to refresh the existing tab instead of opening a new tab.
Is it possible implement this? And on all the browsers?
EDIT: This is different from other SO questions mentioned in the comments since user can open both the websites directly as well and in that case suggested answers doesn't work.
You can do it like this:
Click here
The first time you click that link the page will open in a new tab, but the next times it will refresh the same tab instead.
That's how WordPress refreshes the preview when writing posts.
Edit: This will only work if the other page is opened with this link.
Related
This question already has answers here:
Open a URL in a new tab (and not a new window)
(33 answers)
Closed 4 years ago.
I create event registration websites in a system called Cvent. It is a system specifically designed to allow non-coders to create a registration website where attendees/invitees can come and register, for example, for a convention, or a meeting, or an incentive trip. Cvent also allows advanced coding in order to customize the event site. I code advanced sites.There are times that I am unable to access some coding because it was created within Cvent - think of it is a widget. In a nutshell, I have some links to other reference sites that was coded by Cvent and it did not include target="_blank" within the hyperlink. Is there any script that I can add to a page that will force any existing hyperlink to open in a new tab? Maybe a couple screenshots will help explain my situation....
I am entering in the name and the url to be linked to the name, which Cvent codes for me in the background...
On the front end of the site, it looks like this
screenshot of the front end of this link
When an attendee/invitee clicks on that link, it opens up in this same tab. I need it to open in a new tab. Is there any type of script that will force all hyperlinks to open in a new tab?
I do now how to code javascript so I have not tried anything. I've searched but not really finding anything that helps. It's a pretty specific problem because of the restrictions I'm coding under.
If you are using then put target='_blank'
Or for javascript use window.open()
Hope it will help you,
Thanks.
This question already has answers here:
Is there a way to detect if a browser window is not currently active?
(24 answers)
Closed 3 years ago.
I have a scenario where bootstrap modal popup open logic is added to the master page of our application. The modal popup will be triggered when API call sends status message from API server. It works fine when the user has only one instance of application opened in single browser tab. But the problem occurs when user opens multiple browser tabs of different pages in the application. When the API calls sends the status message the Bootstrap modal popup is triggered across all the tabs which is an issue because the user doesn't want to see these popups in all the tabs.
I have tried the below jQuery onfocus, but this doesn't work. I believe I need to attach an eventlistener to the active browser tab but not sure how to proceed. Could someone please help me in how to find out the active browser tab and trigger the bootstrap popup only in the active tab.
$(window).focus(function(){
console.log('Trigger popup');
});
In your event handler you may use Page Visibility API:
if (!document.hidden) {
// do your stuff
}
This question already has answers here:
Chrome New Tab Page extension steal focus from the address bar
(4 answers)
Closed 4 months ago.
I'm making a Chrome extension that involves putting a text input on the new tab page, and immediately giving focus to that input text when the new tab page loads. After being unable to get focus using traditional methods (e.g. focus()), I stumbled upon this question:
Chrome 27: New Tab Page extension can't steal focus from Omnibox
which states that Chrome has now made it so that you can't steal omnibox focus on a new tab page. Given that Chrome is fine with giving focus to any site that isn't the new tab page, I've been trying to come up with workarounds, but nothing is really satisfactory.
I've tried:
Having the new tab page redirect immediately to locally-stored HTML file, but this still doesn't give focus because the page never had focus while redirecting.
Overriding ctrl+t and cmd+t in a content script to open up a new tab with the contents of a locally-stored HTML file. This works fine, except it seems you can't override cmd+t, so Mac users would be forced to use ctrl+t. Also, some sites (e.g. OneNote online editor) take over ctrl+t, so it doesn't work on every page.
Hosting the page remotely and having the new tab page redirect to it (far too slow).
Suggesting users press tab twice to focus on the input text when opening a new tab :)
Does anyone have any other suggestions as to how you might work around this restriction? It's pretty critical to my extension.
Thanks!
Hello from my question you linked!
On your New Tab Page, include the following JavaScript:
chrome.tabs.create({ url: chrome.extension.getURL("foo.html") });
window.close();
This will create a "normal" tab, and then close the New Tab Page. You can then focus() your input box on the normal tab.
This is what I've done for my Fauxbar extension. It adds a slight delay when clicking Chrome's New Tab button (in terms of how long it takes for your input box to become focused), but I reckon it's better than having to press Tab.
You could also implement chrome.commands to create keyboard shortcuts that users can modify themselves under chrome://extensions > Keyboard shortcuts.
This question already has answers here:
Javascript : Change the function of the browser's back button
(5 answers)
Closed 9 years ago.
Use Case :
I have a webpage which shows popovers for some of the functionalities. The popovers can be considered to be a HTML div which is shown when the corresponding button is clicked. And again go hidden when the cancel button is clicked / browser back button is clicked.
Problem :
Consider that the popover is shown. When the user clicks the back button, he should not get navigated back to the previous page instead only the popover div should get hidden.
How do I add this functionality using javascript to the browser back button?
Thanks in advance
It sounds like you're looking for the HTML5 History API.
A very good intro on how it works can be found at http://diveintohtml5.info/history.html .
Additional information can be found at http://www.whatwg.org/specs/web-apps/current-work/multipage/history.html .
Also, you should look into polyfilling the feature for older browsers. There are plenty of options for doing so including https://github.com/browserstate/history.js , which includes some sample code and even a working demo (http://browserstate.github.io/history.js/demo/).
You can us hash which you append to the URL to fetch history changes.
index.html -> user opens popover -> index.html#popover
Now a click to the back button will redirect back to index.html. Of course this requires some amount of JavaScript code.
You cannot override the button actions in browsers for obvious security reasons, but you may add history entries programmatically, i.e. make the current page show twice in history, so that when the user click on the back button, he/she is redirected back to the same page. Use Really Simple History to achieve that.
I am trying to close a tab using JavaScript on Firefox. I went through a few older questions posted here on Stackoverflow and I understand that Firefox doesn't allow a tab to be closed using JavaScript unless the tab has been opened from JavaScript itself.
However, I could open a blank tab in place of the existing tab using
window.open('about:blank','_self','');.
My question is since the blank tab has been opened through JavaScript, why can't I close it using window.close();?
My question is since the blank tab has been opened through JavaScript
The tab wasn't opened with JS. A window.open call just used the name of an existing tab so the document was loaded there instead of opening a new window.