0

I have two html files.

first.html

<button id="dada">dada</button>

second.html

<div id="chatbox"></div>

I have one js file for both of them.

script.js

$('#dada').on('click',function () {
    $('#chatbox').css('border','3px solid red');
})

When I click on button in the first page i want to change the box in the another page. But this not working? How to do it properly? Thanks!

1 Answers1

0

You probably have some misconception about how javascript engine in the browser works.

Basically, each page (open browser tab) keeps its own DOM representation of html and javascript engine operates within scope, where only this DOM is visible for it.

If you need to communicate with other pages, distinct from the one where your UI engine is running the current javascript threat, you can use cookies in combination with server session.

Other alternative is Local Storage.

  • You're also not up-to-date ;) [Communication between tabs or windows](https://stackoverflow.com/questions/28230845/communication-between-tabs-or-windows). And in case of `window.open()` it's even easier. – Andreas Aug 25 '18 at 16:55