Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I console.log to parent window?

I've got a function that essentially refreshes a table, which works ok, but some of the JS functions don't run. To debug I'm trying to pass data between a popup and it's parent window. Currently I have this function:

$.fn.runFncs = function(isParent)
{
    if (isParent == 1) {
        window.opener.$.fn.compareDates();
        window.opener.$.fn.addStatusIcon();
        window.opener.$.fn.iconTooltips(1);
        window.opener.$.fn.iconTooltips(2);
        window.opener.console.log('test');
    } else {
        $.fn.compareDates();
        $.fn.addStatusIcon();
        $.fn.iconTooltips(1);
        $.fn.iconTooltips(2);
    }
};

and this gets run on an ajax success.

When I hit the button for the ajax, I get my success message etc. but no console.log in my parent window. I've been able to access the parent window before using window.opener and it seems to run ok, just not this time for some reason.

I tried research but either my query was too specific or it was simple "what is console.log" questions so a little stuck here.

Is there an alternative way I can console.log to the parent window? Maybe a document function I'm unaware of?

Thanks! :)

like image 430
treyBake Avatar asked Nov 15 '25 16:11

treyBake


2 Answers

function log(message){
    console.log(message);
}

Put that function in your parent window and call it like so. You basically need to provide a wrapper function that you can access

window.opener.log("Hi");

like image 173
Deckerz Avatar answered Nov 18 '25 05:11

Deckerz


You cannot access directly from one window/tab to anothers's console object, but you can send messages from one window to another. The parent window would get that messages and then it would write it on the console. See this Q&A for more details:

like image 30
Pablo Lozano Avatar answered Nov 18 '25 06:11

Pablo Lozano



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!