send message to iframe from main page in localhost

I am trying to send a message between two files that are in the same folder in localhost, main.php and iframe.php, but the iframe does not listen to it, I have tried to use many target origin like this:

mainpage.php

const iframe = document.querySelector('.iframe');
        
iframe.contentWindow.postMessage("message sent from localhost/mainpage.php","http://localhost/iframe.php");

and inside the iframe.php to listen to the message i use

window.onmessage = function(event) {

    alert(event.data);
}