I have many opened pages with the same domain and the same contents, and what I need is that when I click on a specific button in one tab the other tabs respond and click also the same button, so I would save so much time. I read somewhere here that this function is called "Intercom".
-
This might help http://stackoverflow.com/q/3203530/4759033 – Satej S Jan 28 '16 at 04:02
-
I read it, but unfortunatly couldn't understand it because I am beginner, and I need an easy solution, but thank you for your help! – jeozif.eichoaa Jan 28 '16 at 04:07
-
You could try this approach specifically [link](http://stackoverflow.com/a/18901619/4759033), but with HTML [localstorage](http://www.w3schools.com/html/html5_webstorage.asp) – Satej S Jan 28 '16 at 04:09
-
do you need support old IE ? – jilykate Jan 28 '16 at 04:22
-
no at all, I use Chrome (last version) – jeozif.eichoaa Jan 28 '16 at 04:23
-
Is this for a chrome addon or for a website? – GGG Jan 28 '16 at 04:24
-
for a website, if there is already an addon which do that would be much great – jeozif.eichoaa Jan 28 '16 at 04:28
-
I think you use LocalStorage and setInterval function – Sandeep Jan 28 '16 at 04:42
-
you mean using LocalStorage in the first tab and the setInterval function in the other tabs to check from time to time if the value of LocalStorage is changed, und if it was changed than click the button. did I get it right ? – jeozif.eichoaa Jan 28 '16 at 04:49
-
Yes, you'd use a setInterval to check if the initial value changed and the if it did, you'd run the function related to the click event – GGG Jan 28 '16 at 04:52
-
I was displaying a example below due to the question. If you are familiar with in depth development, the correct route for something of this manner is something like web sockets or signalR. I have used it for my development, but I develop with c# and javascript. Read more: http://www.websocket.org/aboutwebsocket.html – Casey ScriptFu Pharr Jan 28 '16 at 14:13
1 Answers
Sorry for delayed answer, but I wanted to write a good way and not just quick answer for points. This works only if the pages are all under same domain. LocalStorage works that way. Let me know if this works for you, and may have to tweak a small bit, but should give you a idea to work on. There may be a better way, but this is how I would handle it at first.
This would go on each page. Then you can use the page urls, or somthing like a hidden field to make each page unique and obtainable to track when you are currently on it. But the general idea should work.
Happy coding! Hope this helps you!
This works because that script is ran on every page.The only reason it knows what page it is on, is due to what the hidden field value says the current page s, when the script is executing.
This is a very geenral example. But should give you the concept. Since this script runs on every page, and is written generically, itworks out. JUST MAKE SURE THE BUTTON NAME TO TRIGGER EVENT IS THE SAME NAME ON EACH PAGE!
P.S. You could also use window.location to get what page you are on instad of a hidden field.
****HTML EXAMPLE of each page *****
<!-- Each Page -->
<!-- Page 1-->
<div>
<input type="hidden" value="page1"/>
<input type="button" id="cmdButtonThatTriggersEvent" value="Test Buttom"/>
</div>
<!-- Page 2-->
<div>
<input type="hidden" value="page2"/>
<input type="button" id="cmdButtonThatTriggersEvent" value="Test Buttom"/>
</div>
<!-- Page 3-->
<div>
<input type="hidden" value="page3"/>
<input type="button" id="yourButton" value="Test Buttom"/>
</div>
//Make sure ever button name or id is the same on each page.
//That way it is generic. You will also have to track what page //triggered the click event. So make a localstorage hold if the action was clicked to occur, and a localstorage key that holds an array fo all the pages you want this done on. So that way the code can be on every page, and you mark the page off if all page entries were affected, then reset the switch back to null.
****Javascript example for each page*****
<script>
var globalAllPages = ["Page1, "Page3", "Page3"]; //etc.
$(document).on("click", "#yourButton", function(){
localStorage.setItem("trigger_state", "true");
HandleLocalStorageSwitch();
});
$(document).ready(function(){
setInterval(function(){
HandleLocalStorageSwitch();
}, 500);
});
function HandleLocalStorageSwitch()
{
var trigger = localStorage.getItem("trigger_state");
var location = localStorage.getItem("location");
if(trigger != undefined && trigger == "true"){
//now see if this page has ran yet
var dictPages = JSON.parse(localStorage.getItem("current_pages")); //gets the array
var exists = false;
for(var x=0;x<dictPages;x++){
if(dictPages[x]=="this_page"){
exists=true;
break;
}
}
//if it wasnt found then insert it
if(!exists){
dictPages.add("this_page");
$("#this_page_Button").click(); //now trigger this button
}
if(dictPages.length == globalAllPages.length){
//we hit all pages
//then all have been ran, and remove the switch and clear dict
localStorage.setItem("shouldTriggerEvent", "false");
//so now reset and won't run untill one of buttons clicked, then starts process again
localStorage.removeItemKey("current_pages");
}
}
}
}

- 1,672
- 1
- 16
- 36
-
This does work help if the amount of tabs is not fixed and also might note that the "this_page" has to be changed on each page, which would require server-side code generation. And he also did not mention he was using jQuery. – GGG Jan 28 '16 at 05:12
-
thanks bro for the code. I will explain more the situation, they are 22 tabs with the same URLS(they are all Forms). I want just to click the button in the first tab, so just the first tab would be used to click the "submit" button and then should all the other 21 tabs respond and click the "submit" button. – jeozif.eichoaa Jan 28 '16 at 05:51
-
therefore I need just a simple script without considering the other prospects. – jeozif.eichoaa Jan 28 '16 at 06:01
-
Sorry, but that sounds kinda shady, exactly the same URL for 22 tabs... why would you need that.... – GGG Jan 28 '16 at 07:07
-
the places for the soccer games running out always very fast before we could book enough tickets for us. so we must book fast as we can. – jeozif.eichoaa Jan 28 '16 at 07:18
-
could you please tell me how to implement the code in the pages ? – jeozif.eichoaa Jan 28 '16 at 08:31
-
Give a bit. I will create a fiddle. At work currently. But yes, I can. – Casey ScriptFu Pharr Jan 28 '16 at 12:40
-
You could also write the script once, and reference n each page. – Casey ScriptFu Pharr Jan 28 '16 at 13:59
-
I really really thank you guys for your time. I had run the javascript in every page and changed the following items in the script : 1- "ID of the click button" 2-"ID of the affected button". but still not working :( – jeozif.eichoaa Jan 28 '16 at 23:14
-
I dont mind att all, that is why this community is here. Also, I will keep helping until you getting a working example you can implement with what YOU need it for. – Casey ScriptFu Pharr Jan 29 '16 at 03:53
-
It is just that II am a web applications developer for a insurance company, so I may take a bit between post as I cannot be on stack unless break time. lol – Casey ScriptFu Pharr Jan 29 '16 at 03:55
-
Hey Casey, please don't forget to help me, I am waiting for your reply, thanks bro. – jeozif.eichoaa Jan 30 '16 at 00:55
-
sorry, just busy with work and sons b-day. Let me work on it now. – Casey ScriptFu Pharr Jan 30 '16 at 02:53
-
You know, I have never used or heard of intercom.js library. After reading it, I now see what you are trying to do. You want to allow threading to multiple instances f the same page. Let me write up a web scocket example for you, and see if that is what you need. – Casey ScriptFu Pharr Jan 30 '16 at 03:03