Hello,
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.
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.
Anyway, telling your visitor to open the context menu and select which of the three places to open the page is a far better solution to trying to force it to open in a particular spot using JavaScript. Anything you place in the window.open(0 call apart from the first parameter are just suggestions and the browser can be configured to ignore them and always open the page in a certain way.
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.
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?