Solution 1 :

Ok, to check the image that changed, you must go to the other page.
so while redirecting you can post a data to the next page that the image should change. Then after redirecting to the next page, you can request the post data if the image should change. If it should, then change the source, and if it souldn’t, then display the default image.

You can do this in many ways, but if I was there I would do it like this.

<form method="post" id="theForm" action="REDIRECT_PAGE.php">

Then put some hidden fields in that form.

<input type="hidden" name="sould_change" value="yes">
</form>

Then when the button clicked.

Your_button.addEventListener("click", document.getElementById('theForm').submit());

Then on the next page. you can use AJAX or any server-side script like PHP to read the data and put a condition like,

if( $_POST['sould_change'] == "yes"){
    //change the image source
}else{
    //keep it default
}

Problem :

I created one js file which has code to change the image source

function profilefill() {
//alert("Ok In...");
document.getElementById('profile').src = 'profileicon.png';
}

Then I created two web pages one contain a button and a reference to the js file

<button id="signin" onclick="profilefill()" style="height: 40px; width: 90px; margin-top: 5px; 
background-color: black; color:white;">Sign in</button>
<script src="profilescript.js"></script>

And another file where I want to change the image I was given a reference of js file same as previous but the image is not getting displayed.

Comments

Comment posted by Roko C. Buljan

“two web pages

Comment posted by stackoverflow.com/q/28230845/6010889

If you are attempting to communicate between multiple browser tabs/windows, try this question:

Comment posted by Rucha Dixit

@WebSpence can by giving a common js file between two pages we make the connection?…so that when we click the button on a one page image should be displayed on another page

Comment posted by Rucha Dixit

@RokoC.Buljan ya in the sense two pages in the same site

By