I would like to identify browser tabs (on my domain) using JavaScript.
I mean that if user open several tabs with my website and submit web form only on one page I want to notify only this page, even if user moves from this page.
It should be max cross browsers solution.
P.S. One of the possible solutions is using "window.name" property, but I do not want to use it because somebody else can use it.
P.S-2: I found one more possible solution: using sessionStorage. It supported by FF3.5+, Chrome4+, Safari4+, Opera10.5+, and IE8+. Oooohhh, I need IE7!!!!
Thank you in advance!
I don't think this can be done. Each browser tab that is opened is basically like a new browser instance. Just like if the user opened another browser. One tab knows nothing about the other tab by design. This is how it should be. Can you imagine the implications if a web site developer could add code to their page to "see" what other sites you have opened in your browser?
window.name is the only persistent data element you can use for this purpose, as described your requirements.
I want to notify only this page, even if user moves from this page.
This is impossible. Once a user navigates away from a page, you lose control over that tab. You can't push to a page, it needs to make a server request FROM that page, even if it's ajax.
Using sessionStorage. It supported by FF3.5+, Chrome4+, Safari4+, Opera10.5+, and IE8+.
For IE7 using "window.name" property.
Related
the requeirment is that I want to avoid the specific web page to save to bookmark,
and is there someway to acheive this funcion just use some code, maybe add or js code . thanks
The answer is no, the user can always bookmark a page as this is browser function, but you can use sessions. Then make sure that any request for a page
must have an active session id or it returns an error or redirects to the home page. The user can bookmark the page but the bookmarks will then only work for a short time (until the session expires). This also has the added benefit of
making the site impossible to index by search engines.
The closest you're going to get is if you open another window using JavaScript as you can control whether the menubar and toolbar are displayed.
window.open(
"https://www.google.com/",
"Google",
"resizable,scrollbars,status");
However, this is likely going to be blocked by their popup blocker.
I have the following code in which I am trying to open multiple mailclient
It works in Firefox but dont work in Chrome
<button class="button">Open Email</button>
$(document).ready(function(){
$('.button').on('click',function(){
window.location.href = "mailto:user#example.com?subject=Subject&body=message%20goes%20here";
window.location.href = "mailto:user#example.com?subject=Subject2&body=message%20goes%20here";
});
});
Here is the fiddle to it
Anyone knows whats the reason behind this , or is there any other technique to do this?
Thanks
Chrome allows only one opened window per user action. If opening new browsers window was the issue, you could tell the popup blocker to allow it, but this is not possible when launching email windows. You could either require two user actions (e.g. two buttons) or you could make a web based mail form to do the same thing (if you're using the mail client of tracing purposes, just make it send a copy to yourself.
If you want to open multiple links you shouldn't use window.location.href, it opens link in current window and you cant really have more than one link opened in one window. You should use window.open(your_url) for that, but beware, it will create popup windows.
From a browser perspective mailto is a link like any other, so assigning it to window.location.href twice in a row is like fast-clicking two links in a page, browser will process only one of them.
And the last, code from your question not working even in FF if you use browser based mail client, like gmail.
You could supply 2 links for the user tp open the email clients manually, you could also open the client, refresh the page (indicating something on the url for the second one) and then open the second one?
I would like to know on my web page whether the user has loaded the page normally through clicking a link, entering the URL or whatever, or whether the page is from the history and the user came there by pressing the Back button in the browser (or using a hotkey...).
So essentially I'm looking for a method like window.location.canGoForward(). Does something like this exist? If not, what are the workarounds?
I don't care about what happens when the Back/Forward button is pressed, there's plenty of content about that on the web. I just want to query the loaded page about whether it is the latest in the browsing history or not. Wide browser support is appreciated.
You could count the length of the history variable to see if they are new to your site. Here are some helpful links
http://www.w3schools.com/jsref/obj_history.asp
https://developer.mozilla.org/en-US/docs/DOM/Manipulating_the_browser_history
https://github.com/browserstate/History.js/
Using JavaScript, is it possible to add a bookmark in Firefox directly, without opening any dialog box? That is, I want the user clic on a link and that the bookmark is automatically created, without the need to any further step.
Fortunately, no. It would be a horrible breach of security.
Could be a different story in the context of a Firefox Extension, but I assume you are asking for a normal web page.
If it was possible, any possible website would be able to create any kind bookmark, without the user even noticing.
As a user, I certainly hope this is not possible ^^
(And, as a developper, I don't think it is)
I am creating a Firefox extension where I need to find out what was the last location visited in another window. Here is an example of what I mean. I present the user with a list of sites from a main interface window. The user clicks on one of the sites and a new window is opened to that site. From there, the user will navigate the site in the new window and will eventually stop browsing or close the window. I need to find out what was the last visited location from that window. Also, the user may be navigating more than one site at a time, so there could be many windows open. I need to know what was the last location for every one of them. So far, the only way that I got it to work is to use a timer and poll the new window every second for document.location.href. There must be a better way.
As far as I know this is not possible in (pure) Javascript due to security/privacy considerations. On the other hand, since you are writing a Firefox plugin you have additional mechanisms you can use.
For instance, you can create a greasemonkey plugin that is applicable to every site. This plugin will record the href using GM_setValue(). The main plugin will read this information via GM_getValue().