【问题标题】:I can edit the content before printing?我可以在打印前编辑内容吗?
【发布时间】:2017-12-09 08:47:02
【问题描述】:

第一个运行的 chrome 插件。我没有详细信息。

在我打印This link的内容之前,我想得到具体的部分。

<table class="receiptSectionTable2Col" >

我怎样才能打印这个表的内容。 这可能吗?

【问题讨论】:

    标签: google-chrome google-chrome-extension extension-methods


    【解决方案1】:

    我认为来自this问题的this回答会对您有所帮助:

    HTMLElement.prototype.printMe = printMe;
    function printMe(query){
      var myframe = document.createElement('IFRAME');
      myframe.domain = document.domain;
      myframe.style.position = "absolute";
      myframe.style.top = "-10000px";
      document.body.appendChild(myframe);
      myframe.contentDocument.write(this.innerHTML) ;
      setTimeout(function(){
      myframe.focus();
      myframe.contentWindow.print();
      myframe.parentNode.removeChild(myframe) ;// remove frame
      },3000); // wait for images to load inside iframe
      window.focus();
     }
    

    在您的情况下的用法:

    document.getElementsByClassName("receiptSectionTable2Col")[0].printMe();
    

    【讨论】:

    • 首先感谢您的回复。这个例子我做不到...developer.chrome.com/extensions/examples/api/bookmarks/…
    • 我不知道你到底需要什么,但我猜你可能需要content script 来实现它。如果您希望我帮助您,您应该编辑您的问题以更具体地说明您遇到的问题。
    • 我想用58mm芯片打印机打印上面地址中指定的页面。我只想打印该页面上的指定位置(指定的 div 内容)。我想通过 chrome 扩展打印示例来做到这一点,但我做不到。当我按下打印图标时,我想打印页面sezgin.net.tr/fatura.html上的特定区域。
    • @alon3wolf 如果您访问该站点并粘贴此函数并在 chrome 开发人员控制台 (ctrl+shift+j) 中调用它,系统将提示您仅打印所需的部分。要通过 chrome 扩展实现这一点,您需要创建一个新扩展并将此代码放入内容脚本中。我建议您研究更多关于扩展及其architecture
    猜你喜欢
    • 2019-05-04
    • 2019-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-25
    • 2023-03-30
    相关资源
    最近更新 更多