HTML window popup and proper degrade for iPad - javascript

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.

Related

WIndow.name not setting window name in a way that target identifies

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.

opening a target blank page with the parent page in front

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.

Opening a link in a different active window

I have two browser windows open. One is a website assistant, the other is the actual website that assistant is related to.
If a user clicks a link from the assistant window, is it possible to trigger the loading of that page/link to appear on the second window instead of the assistant window?
I have no code for this, simply a question before I go any further.
A perfect example is www.ikea.co.uk. Click 'ask anna' in the header, and ask her 'how much is a bed'. The links it provides will open in window #1.
How do you open the windows? With Javascript? Define a name to each frame/window and call for them on links. Something like that:
<iframe name="two"><iframe>
link

Redirect after clicking an external link and only open one tab/window

I have created a jsp for external clients of my application to use to link to the web client. They can specify which client they are in the URL so that when the link opens a window it is named and any other links from that client will open in the same window. Here's an example URL:
mysite.com/redirect.jsp?fromClient=mine&page=awesome
The problem is that when you click on this link, for example from an email digest, it opens the redirect.jsp page which uses window.open() to open the desired page. From the above link, the page that would open would be:
mysite.com/index.jsp?page=awesome
So then I have two pages open, when really I only want one. And since I'm not using javascript to open the first page (it's a link), I can't use window.close() to close it. I've tried working around using window.open('','_parent','') and window.open('','_self','') but neither works.
I know there has to be a better way to redirect than to open a second window from my jsp page, but I don't know what that better way is. Thoughts?
EDIT
Primary goal is for users of external clients to be able to click links in that client and have all the links take them to the same window/tab in a browser. I'm using window.open right now because I can parse the link and get the client name and then supply that in the window.open function.
EDIT 2
I always end up being too vague in these questions. Ok, here's the setup:
An email digest contains a link that looks like
mysite.com/redirect.jsp?fromClient=emailDigest&pageNum=4
Currently, when that link is clicked on, it opens a browser (duh) and then the redirect.jsp page parses that link to get the client name, in this case emailDigest. It then calls window.open('mysite.com/index.jsp?pageNum=4','emailDigest'). This creates a new window with the name emailDigest unless a window/tab with that name already exists, in which case it merely updates the URL in that window with the new one.
I want to either be able to close the original window (the one with the redirect.jsp address) or not have to open that initial window at all.
NOTE
As there are many different clients that want to be able to do this, I cannot guarantee that they will be creating the link with HTML so the target attribute is not the answer.
The correct answer is "No, it cannot be done". If you do not open a window with Javascript then you cannot close it with Javascript. I would always have to create at least 2 windows, which is not what we wanted.
I think you're looking for window.location instead of window.open.
Please use window.location.replace("http://mysite.com/index.jsp?page=awesome");
Reason :
replace(url):Replace the current document with the one at the provided
URL. The difference from the assign() method is that after using
replace() the current page will not be saved in session history,
meaning the user won't be able to use the Back button to navigate to
it.
As haynar says above, why do you open a window and not either:
<!-- content contains the refresh delay in seconds and the target url -->
<meta http-equiv="Refresh" content="1; URL="http://mysite.com/index.jsp?page=awesome">
or use javascript to do the same:
window.location.href = "http://mysite.com/index.jsp?page=awesome";
either works fine and will leave you with one window open.
To get the named window use a targeted link:
Mysite.com
This will automatically set the name property of the opened window.

Href link followed by onclick events when we press a button

Presently I have a button which will open a popup and it also pass some parameters(like id,name) in the same page.But now i want to open a welcome page(href link) and there it should the popup page with that id and name what i have passed.My onclick event is a javascript code which will open a popup.I have used something like this
This can be done in several ways. One simple way is:-
Redirect the user to your welcome page when onclick is fired.
At the same time of redirection, pass the information u want to show in the popup as get parameters to the welcome page.
Once the welcome page is loaded, check whether the particular get variables are set. If they are set, show a popup window in that page with the information passed via GET.

Categories

Resources