-1

My Code:

$('.classname').on ("click" ,function() {
    var newpage = "Html Elements for blank page";
    var mywindows = window.open("","_blank","");
    mywindows.document.open() ;
    mywindows.document(newpage);
    mywindows.document.close() ;
});
<button class="classname">Click here</button>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

I want to make it short By Using:

$('html').html('my html elements');

but I can't success to use this, It Always shows result in the current page, and opens a blank page, and I don't have any idea to fix it! Here is the code:

 $('.classname').on ("click" ,function() {
        var newpage = window.open('','_blank','');
       newpage.$('html').html('my html elements are here');
    });
Zsolt Meszaros
  • 21,961
  • 19
  • 54
  • 57
Mahdi
  • 113
  • 2
  • 8
  • `document` is not a function, you're probably missing `.write` from here: `mywindows.document(newpage)`. The second snippet won't work, since there's no jQuery loaded on a blank page. – Teemu Dec 04 '20 at 21:15
  • @Teemu yep, but I'm trying to use jquary $() to write it on blank page, any idea? – Mahdi Dec 04 '20 at 21:17
  • `newpage.$` refers `$` on that blank page. See https://stackoverflow.com/q/9399354/1169519 . – Teemu Dec 04 '20 at 21:24
  • jQuery keeps an internal reference to `document` that refers to the document it was included on. You can use jquery methods on elements of other documents, but the results should be considered flimsy at best, unless you know which methods refer to the internally stored `document` and which ones don't. Best bet would be to just use js instead for manupulating `newpage`. – Kevin B Dec 04 '20 at 21:29

1 Answers1

-1

Document is not a function to use parameters in it.

Else you can not use open and close function with document.

  • Note: answers that are very brief and/or are questions back to the poster should probably be comments. You only need 50 rep points to comment under a question - could you move this there? – Tyler2P Dec 05 '20 at 10:21