Note that there are some explanatory texts on larger screens.

plurals
  1. POdocument.write in Chrome Extension
    text
    copied!<p>I'm new to this so please bear with me. I am trying to write a chrome extension that does the following:</p> <ol> <li>Detect www.website.com/anypage.html. If this website is detected, then do the following.</li> <li>Don't load the URL. </li> <li>Instead, write a blank document with a hyperlink to www.website.com/anypage.html?ie=UTF8</li> </ol> <p>The script is set to run at document start (in the manifest). </p> <p>Here is my code:</p> <p>Detect URL:</p> <pre><code>var regExp = /website.com/gi; var match = 0; testString = window.location.href.toString(); if(regExp.test(testString) { match = 1; </code></pre> <p>Write blank document with link to the URL with the UTF8 encoding tag:</p> <pre><code>document.write("&lt;a href=" + window.location.href + "?ie=UTF8&gt;Title of Link&lt;/a&gt;"); </code></pre> <p>This doesn't work as expected, and just shows a blank page. Anyone have any ideas?</p> <p>Thanks!</p> <hr> <p>EDIT: Here is the full code:</p> <pre><code>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("&lt;a href=\"" + newLink + "\"&gt;Link&lt;/a&gt;"); if (matchLink) { tagUTF(); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload