English 中文(简体)
文件: Chrome
原标题:document.write in Chrome Extension

我这样说了不起。 我正试图写一下长篇大论,其中:

  1. Detect www.website.com/anypage.html. If this website is detected, then do the following.
  2. Don t load the URL.
  3. Instead, write a blank document with a hyperlink to www.website.com/anypage.html?ie=UTF8

文字在文件一开始(在清单中)。

我的守则是:

侦查:

var regExp = /website.com/gi;
var match = 0;
testString = window.location.href.toString();
if(regExp.test(testString) { 
match = 1;

与URL和UTF8编码标签链接的书写空白文件:

document.write("<a href=" + window.location.href + "?ie=UTF8>Title of Link</a>");

这只是一个空白页。 没有人有什么想法?

感谢!


EDIT:这里是一部完整的法典:

checklink(); // If there is a match, then checklink will return a 1. If it s already     tagged, it will return a 5.
var matchLink = null;
if (checklink() === 1) {
matchLink = window.location.href.toString();

if (checklink() != 1) {
matchLink = null;

function checklink() { //checks to see if the current URL matches website.com
var regExp = /website.com/gi,
testString = window.location.href.toString(),
match = 0,
tagged = 0;

if (regExp.test(testString)) { //if there is a match, returns 1
match = 1;


var regExp2 = /UTF8/gi;
if (regExp2.test(testString)) { //if UTF8 is found, then it returns 5
tagged = 5;

return(match + tagged);


function tagUTF() {
if (matchLink) {
var newLink = matchLink + "?ie=UTF8";
document.write("<a href="" + newLink + "">Link</a>");


if (matchLink) {
tagUTF();
}
最佳回答

胶卷的内容说明可以进入OMM,因此,你只能用新的节点取代本页的正文内容,代之以您的封顶,要么使用dom操纵方法,要么使用超文本:

document.body.innerHTML = "<a href=" + window.location.href + "?ie=UTF8>Title of Link</a>";

请注意,这一假设是,正在对OMM进行操纵的贾瓦文作为“连续文字”适当添加 Chrome号:

rel=“nofollow”http://code.google.com/chrome/extensions/content_scripts.html

EDIT:

Here is the code I used to make it work for me locally:

清单。

{
  "name": "Test",
  "version": "1.0",
  "description": "Test",
  "permissions": [
    "<all_urls>"
  ],
  "content_scripts": [
    {
      "matches": ["<all_urls>"],
      "js": ["内容说明.js"],
      "run_at": "document_end"
    }
  ]
}

内容说明.js

document.body.innerHTML = "<a href= test >test</a>";
问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签