0

I have a Tampermonkey script that opens another tab when a button is click, I then want it to reload the parent tab whilst focused on the new tab that was opened.

I have tried all the suggestions in this SO question but none of them work. Reload parent window from child window

Some of the suggestions give me the error "failed! Permission denied to access property "reload" on cross-origin object"

if (window.location.href.indexOf("loc1/?q") > -1) {
window.parent.location.reload(true);
} else if (window.location.href.indexOf("loc2/?q") > -1) {
var parameters = '\"' + mac + '\", \"' + ln + '\", \"' + num + '\"';
var btnEle = "<button id='add' type='button' onclick='passData(" + parameters + ");' class='btn btn-outline-success btn-sm'>Add</button>"
var btnAdd = $(this);
btnAdd.append(btnEle)
}

unsafeWindow.passData = function(mac, ln, num) {
(async function(){
    GM.setValue("mac", mac);

    var prev = mac;
    var search = prev.replace(/\:/g, '%3A');
    var searchUrl = 'https://url.com/loc1/?q=' + mac
    var loc1Tab = window.open(searchUrl, "_blank",);
    loc1Tab.focus();
})();
}
Gary
  • 318
  • 3
  • 14

0 Answers0