window.open and $(document).ready

前端 未结 2 820
南笙
南笙 2021-01-15 16:20

I am trying to make a bookmarklet that opens a popup window. Inside this window is a list of CSS classes that once selected, highlights that object on window.opener

相关标签:
2条回答
  • 2021-01-15 16:28

    Does the $(document).ready fire if you add the following line before the return false?

    testpopup.document.close();
    

    This is a wild guess though, and I haven't tested this.

    0 讨论(0)
  • 2021-01-15 16:36

    Indeed the document.ready never fires.. (i don't know why ..)

    But you can add your script after the html and remove the document.ready since the document is always loaded at that time ..

    function makepopup(){
     var popup = '<!DOC'+'TYPE HT'+'ML PUBLIC "-//W3C//DTD HT'+'ML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">' +
     '<ht'+'ml><he'+'ad><title>Test</title>' +
     '<scr'+'ipt type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></scr'+'ipt>' +
     '</he'+'ad><bo'+'dy>' +
     '<div id="wrap">' +
      'testing popup' +
     '</div>' +
     '<input type="button" value="Click Me" />'  +
     '</bo'+'dy></ht'+'ml>'+
     '<scr'+'ipt type="text/javascript">' + 
     '$(":input").click(function(){ alert($(window.opener.doc'+'ument).find("#test").html()) });' +
     '</scr'+'ipt>';
     var testpopup = window.open( '','test','toolbar=1,location=0,status=0,width=500,height=450,scrollbars=1' );
     testpopup.document.write(popup);
     return false;
    }​
    

    This works ..

    [UPDATE] BUt the method from Aistina is the correct way to go.

    0 讨论(0)
提交回复
热议问题