0

I am developing and app using Cordova(phonegap) which uses HTML and CSS and javascript and jquery, in one of the pages of my app I have a button which opens a URL for a question from the user.by using this code:

var URL="https://question.com/q1";
var ref=window.open(URL,'_parent','location=no,clearcache=yes,toolbar=no,titlebar=no');

now because I don't want to show the user the URL which they have been redirected I am removing the title bar which includes a close button.and now I don't have any button to close the page.I want to know if is it possible to add a close button to the parent page and show it when we open the new URL?

Sanyami Vaidya
  • 799
  • 4
  • 21

1 Answers1

0

HTML:

<button id="closeButton">close</button>

CSS:

#closeButton { 
  display:none; 
}

JS:

var URL="https://question.com/q1";
var openedWindow = window.open(URL,'_blank','location=no,clearcache=yes,toolbar=no,titlebar=no,width=600,height=600');
$('#closeButton').unbind().on('click', function(){
    openedWindow.close();
    $(this).hide();
});
$('#closeButton').show();

The second param "_blank" is what opens the new window instead of overlaying like you mentioned ("_parent"). You can set different initial width and height. Now with this solution, some browsers will flag this as a popup and will require permissions to open it (this is the more user-friendly way to do it instead of forcing opening a window) but if you want to by pass it, you can reference to this topic: Bypass popup blocker on window.open

Samuil Petrov
  • 542
  • 1
  • 13
  • 24