team1504 — 2011-12-30T22:39:59-05:00 — #1
I was wondering if there was a way once could check if a page was opened in a new tab, by right-clicking and clicking the "Open in New Tab" option in most browsers, or if a page was opened in a new window, by right clicking on the link and pressing the "Open in New Window" in a browser?
Is there a way one could do this in js? or, and i know this is not the forum to ask, but if possible in html or php?
I am asking here because js seems like it would be the most-capable of doing this. Also if it could be done in jQuery, that would be convenient for me
Finally, the reason why I want to do this is to detect if a link from / in my site was opened in a way besides the default action i put in the html <a> tag's target attribute.
Thank you for you help and please post any Questions, Comments, Concerns, or Solutions.
felgall — 2011-12-30T22:53:49-05:00 — #2
The second parameter of window.open() provides the name of the window or tab to open it in. If you use '_blank' then it will always open in a new window unless your visitor has overridden that option. If you specify a value that doesn't start with an underscore and a window or tab (or frame) already exists with that name then the page will be loaded in that existing window or tab. The fourth parameter can be set to true or false to indicate how the existing history associated with that window or tab should be treated.
team1504 — 2011-12-31T00:01:36-05:00 — #3
Well I dont want to dictate how they open the link. I want to know how they opened the link.
And if they opened the link in a new-tab or new-window then execute some js
paul_wilkins — 2012-01-03T07:18:22-05:00 — #4
Sorry no, web browsers do not give that that sort of information to the scripting environment.
team1504 — 2012-01-04T14:29:18-05:00 — #5
oh okay. well it was worth a shot.
I'll just have to exhibit less control on my site's environoment then...:nono::mad::confused::eek:
haha thank you!
mittineague — 2012-01-07T23:46:51-05:00 — #6
Wouldn't testing for
paul_wilkins — 2012-01-08T03:04:04-05:00 — #7
Yes, that should work in enough environments. If it's equal to one you can assume that they're in a new window or tab. You just won't be able to determine from that which of those two it is.
team1504 — 2012-01-10T17:47:09-05:00 — #8
First of all, Thank you both for still posting even though I had given up.
Hmm, well for the purposes of the site i was making, I don't need to distinguish between an open tab or open window just know that its one of them.
So how would one test for window.history.length to do this?
paul_wilkins — 2012-01-10T18:03:18-05:00 — #9
You would compare window.history.length to a number
team1504 — 2012-01-10T21:08:53-05:00 — #10
Well I thought so. Sorry if that sounded rude, I didn't mean it to be. I should have made it clear that I figured one would have to do that. A question that I am clueless on is that number would you compare the length of the history to?
Also does window.history.length give the length of pages in the history of the specific window /holidays tab it is run in?
If so then would I compare the value to 0. Meaning the page was either the users home-page or opened in a new-window or new-tab, right?
paul_wilkins — 2012-01-10T21:15:03-05:00 — #11
You would compare the length of the history to the number you would expect on a new page.
No, because the history also contains the current page that you are on, so you would compare it with 1.
You can get some further details about it at Manipulating the browser history
team1504 — 2012-01-10T22:23:28-05:00 — #12
Ah okay. 1 not 0 because they are at a page, which makes it in the history. I will give it a try tomorrow.
Thank you all for your help!
system — 2014-10-07T21:45:26-04:00 — #13
This topic is now closed. New replies are no longer allowed.