te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>javascript - Load iframe into the page, using Chrome Extension content script - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Load iframe into the page, using Chrome Extension content script - Stack Overflow

programmeradmin3浏览0评论

I am able to add HTML/CSS dynamically into the page using a content script. But I tried adding an iframe tag, and ran into a little bit of trouble.

Here is my code:

  const myIFrame = `
    <iframe src="${modalIFrameURL}"></iframe>
  `;
  let div = document.createElement('div');
  div.style.zIndex = 9999999;
  div.innerHTML = myIFrame;
  document.body.insertBefore(div, document.body.firstChild);

note the modalIFrameURL value is:

chrome-extension://omelijcoklpokoeobkpepoipjpbakoeo/modal-iframe.html

This is what I get at the top left of the page:

If I hover over the gray fail box, it says:

Requests to the server have been blocked by an extension.

Does anyone know how to load an iframe from a content-script? What I am looking to do is load an HTML file from my Chrome Extension codebase into that iframe.

I am able to add HTML/CSS dynamically into the page using a content script. But I tried adding an iframe tag, and ran into a little bit of trouble.

Here is my code:

  const myIFrame = `
    <iframe src="${modalIFrameURL}"></iframe>
  `;
  let div = document.createElement('div');
  div.style.zIndex = 9999999;
  div.innerHTML = myIFrame;
  document.body.insertBefore(div, document.body.firstChild);

note the modalIFrameURL value is:

chrome-extension://omelijcoklpokoeobkpepoipjpbakoeo/modal-iframe.html

This is what I get at the top left of the page:

If I hover over the gray fail box, it says:

Requests to the server have been blocked by an extension.

Does anyone know how to load an iframe from a content-script? What I am looking to do is load an HTML file from my Chrome Extension codebase into that iframe.

Share Improve this question asked Feb 4, 2018 at 5:19 Alexander MillsAlexander Mills 100k165 gold badges532 silver badges909 bronze badges 10
  • If you make a new profile and only install the extension you're testing, does the issue still occur? – Wesley Smith Commented Feb 4, 2018 at 5:21
  • Right so you think another extension is blocking the iframe? If that's the case, then my iframe solution is not gonna work, simply because other users will likely face the same problem I am facing. Other users will have extensions that block iframes or whatever...right? – Alexander Mills Commented Feb 4, 2018 at 5:53
  • yeah even with a new profile and just my extension loaded, I get the same error: Requests to the server have been blocked by an extension. – Alexander Mills Commented Feb 4, 2018 at 5:58
  • 1 Possibly given the content of the message. I would start a new profile and add one extension at a time till it happens again to narrow down the extension causing the issue. Then, see why that extension is causing the issue. – Wesley Smith Commented Feb 4, 2018 at 5:58
  • 1 Thats possible depending on the styling of the iframe. Right click on the edge of the frame and click "inspect". That'll open the dom inspector in the dev tools console. Hover over the iframe node in the console and you should see clearly all the space the frame takes up. Then you can play with the css for the frame in the right had CSS panel till you get it to where it doesnt interfere with the page. – Wesley Smith Commented Feb 4, 2018 at 19:46
 |  Show 5 more ments

1 Answer 1

Reset to default 15

I ran into this a few weeks ago. I found that adding a "web_accessible_resources" section to my manifest.json file resolved it.

From what you are calling out, it should look like:

"web_accessible_resources": [
    "modal-iframe.html"
],

https://developer.chrome./extensions/manifest/web_accessible_resources

Just make sure that you are including "modal-iframe.html" in your extension build directory.

Hope that helps.

发布评论

评论列表(0)

  1. 暂无评论