Add a frame to the bottom of a web page using a Gr

2019-08-03 06:50发布

问题:

Is there any way to add a frame to the bottom of a web page using a Greasemonkey script?

I want to write a script that adds http://www.google.com at the bottom of every web page, inside a frame.
I also want the width and height of the frame to be the same as the height of the page that is inside it.

回答1:

This is 3 questions in one.

  1. Adding an <iframe> is easy, by itself:

    $(document.body).append (
        '<iframe src="http://{SOME_PAGE_BESIDES_GOOGLE!}.com/">'
    );
    


  2. But, Google will not   let you   load it in an <iframe> -- blocking that with a variety of tricks, and the Terms of Service.
    Plenty of other sites -- including Stack Exchange sites -- also block operation from within an iframe.

  3. There is a slight chance that you could load framed-blocked pages in an <object>, if, and only if, the target page server has Cross-origin resource sharing (CORS) set to allow it.

    It's a safe bet that your target page(s) don't have CORS set that way. ;-)   But, if they did, then the code would be like:

    $(document.body).append ( '                                     \
        <object type="text/html" data="http://www.google.com/">     \
        </object>                                                   \
    ' );
    


  4. Finally, for those cases when you can actually load an <iframe> (or <object>), you would need to communicate the page size back up to the container/master/target page, from the loaded iframe.

    To do that, see How can two instances of a userscript communicate between frames?.



For Google on every page, your best bet is to use the Google Custom Search API.