My use case:
User already has web app open in a browser tab
An email is sent to the user with an anchor tag that takes user to a specific page in the web app
On clicking, the initial tab is repopulated with new page
To do this the anchor tag is formatted like <a target="webapp" href="example.com" >Click Here</a> and I have a tiny bit of javascript, triggered on load, in my web app like this window.name="webapp"
What is working:
If I test to make sure the window name was with window.name="webapp", doing console.log(window.name), it confirms that it was
If I click the link from the email and the web app isn't open yet a new tab opens. If I click that link again the tab that initially opened refreshes.
What isn't work:
If the user initially navigates directly to the web app (not via a link) and then clicks the link from the email, the link opens a new tab instead of repopulating the open tab. In this scenario I still get the correct window name in the console log but not the functionality I'm looking for.
Looking for insight into how to get this to work or if there's a better solution to this use case.
Related
My web app homepage has many card elements (like Pinterest), each click to a card will create a popup window instead of going to the associated page. I want to change the address bar url so that when users refresh the homepage with the popup window, the browser will go to the associated page. And each click to the card element will also push the associated page url to the browser history. Basically, the concept comes from Pinterest.
When I use $location.path() or $location.url(), they both redirect.
You can use the history from the window.
window.history.pushState("abc", "Title", "/the_new_happy_url");
You don't need JavaScript. You can open links in a new window using the target attribute, like so:
Click here!
I have one-page JS tool. When some event is fired, user got an e-mail. In it there is a link to my tool. But I do not wand to open new tab with duplicated tool to let user do smth. with fired event.
I want to redirect him from e-mail to already opened tab (if it exists, or simply open new) and set new data.
Like this: suppose user has tab with http://example.com/ opened, then he got an e-mail with link to http://example.com/?open=sometab_int_the_tool. In normal way, when user click on that link, he got duplicated tab with http://example.com/. But obviously, the better way is to open existed tab and send to it command to open some tab.
How can I do this?
I am simply creating an HTML page, where I am using target="" in the link which opens up the page as target="_blank".
For Instance,
link
What I want is, when the user clicks on it, the blank page, which opens up, should open, but the main page from where the link is clicked should stay. Right now, it is acting like "target="_blank", which onclick shows the page redirected.
Is this possible ?
Not an exact answer to this problem but you can do a nasty trick to make it look so by opening the current page in new tab and loading the link in current tab. One disadvantage with this would be that current page will be in a tab next to new page.
You can do something like
<a href="https://google.com" onclick="window.open('#','_blank');window.open(this.href,'_self');">
I don't think you can control the browser behavior by manipulating which tab to focus, it is like letting me make changes to your bank profile information illegally. There is really nothing much you can do about it.
I have a "quizzes" website where a list of quizzes is shown and each link opens a popup for a cute little quiz:
Start quiz ยป
On a desktop, I can have the user return to the quiz list with:
<a onClick="window.close()" href="#">Return to quizzes</a>
There's a couple of problems with this approach, and I'd like something better:
If the user arrived at this page with a target="_blank" link, then the "return" link should use window.close to get them back where they started
If the user agent ignores target="_blank" like iPad/Chrome then the "return" link should do a normal hyperlink to quizzes/index.htm
If the user came into quizzes/stable-tachycardia.htm via a direct link, the "return" link should do a normal hyperlink
Is there a good solution that covers each use case?
I'd have it link to a JavaScript function which checks for the presence of window.parent. If the parent window exists, open the desired URL in the parent and close the current window. If there is no parent, just open the URL in the current window.
I'm in a discussion with my co-worker. We have a web application in a tabbed browsing environment, say with 2 tabs open. Tab2 has a link to tab1, when I click the link, it opens tab1 in a new tab. We want to detect if tab 1 is already open, if so then set focus to tab1 (and not open a new window).
He has gotten this working in a broswer window environment, but says it is not possible in a tabbed environment.
Is it possible to for javascript to determine if tab1 is already open and then just set focus to that tab?
It is only possible if the webbrowser is already preconfigured to open links with a target in a new tab instead of new window and sets focus to it itself when you have given the links the same target name.
E.g.
link1
link2
link3
In other words: you're dependent on the client/webbrowser used. You have no control over it from the server side on.
In Firefox for example, the client should have checked both the Open new windows in new tab instead and When I open a link in a new tab, switch to it immediately options to get your requirement to work.
(as you see, the last one is disabled in mine)
You should instead create a separate document with a DOM-based tab, and iframes pointing to the real pages. Then you could easily set 'focus' to the correct tab when needed.