What is the answer to this issue where the entity name is required to directly come after the "&" in the entity reference?

Whenever I insert the code into my Blogger platform, an error pops up stating: The entity name must directly follow the '&' in the entity reference Here is the code:

<script>
if (typeof bc_blocks == "undefined" && window.bc_blocks === undefined) {
    var bc_blocks = document.getElementsByClassName("bigClickTeasersBlock");

  if (bc_blocks.length) {
    var bc_blocks_ids = [];

    for (var i=0; i<bc_blocks.length; i++) {
      var bc_el_id_str = bc_blocks[i].id;
      var bc_el_id = parseInt(bc_el_id_str.substring(bc_el_id_str.lastIndexOf("_") + 1));

      if (bc_el_id>0) {
        bc_blocks_ids.push(bc_el_id)
      }
    }

if (bc_blocks_ids.length&&bc_blocks_ids.length<5) {
 var bc_scr = document.createElement("script");
 bc_scr.src = "https://trandgid.com/lhzbsrfkjf/js/" + bc_blocks_ids.join("/") + "?r=" + encodeURIComponent(document.referrer) + 
 "&" + Math.round(Math.random()*99999);
 bc_scr.setAttribute("async","");
 document.body.appendChild(bc_scr)
       }
    }
  } 
</script>

I am attempting to display an advertisement on my webpage.

Answer №1

The issue you're facing with Blogger is connected to how you are attempting to incorporate an external script. Blogger likely imposes restrictions on the characters permissible in the URL for security purposes.

Here's where your code is falling short:

  • encodeURIComponent(document.referrer)
    : This particular line encodes the referrer URL, which may contain special characters such as &. When you append "&" after that, it generates an invalid entity reference because the "&" is interpreted as the beginning of an HTML entity rather than a literal character.

To make the code compatible with Blogger, here are potential solutions:

Option 1: Utilize a redirect script

  1. Create a new HTML file containing the following code:
<script>
  var bc_blocks_ids = [/* Your ad ids here */]; // Replace with your actual ad IDs
  var redirectUrl = "https://trandgid.com/lhzbsrfkjf/js/" + bc_blocks_ids.join("/") + "?r=" + encodeURIComponent(document.referrer) + "&" + Math.round(Math.random()*99999);
  window.location.replace(redirectUrl);
</script>
  1. Upload this HTML file to your web server.

  2. In Blogger, instead of embedding the original script, add an HTML gadget and paste the following code:

<iframe src="**Your uploaded script URL**" width="1" height="1" style="display:none;"></iframe>

Option 2: Adjust the original script (Less secure)

Note: The second option might go against Blogger's terms of service. It is advisable to opt for option 1 for enhanced security.

  1. Modify the line:
+"&" + Math.round(Math.random()*99999);

to:

"%26" + Math.round(Math.random()*99999);

This substitution changes the & character into its encoded form (%26).

Essential Note: Altering Blogger's built-in functionalities could potentially breach their terms of service. It is strongly advised to adhere to approved ad serving methods. Prior to implementing any custom solution, ensure to consult Blogger's documentation regarding approved ad serving methods.

These strategies should rectify the error and enable you to insert the ad on your Blogger page. Always bear in mind to follow Blogger's directives when incorporating custom scripts and features.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Having an iframe at the bottom of the page is causing unnecessary white space below the

I currently have an iframe placed in the footer of my website. When I try to set the height of the iframe to match the height of the footer, it results in unwanted white space appearing below the iframe. The issue can be seen here: JSFiddle To fix this p ...

Adjusting font size, contrast, brightness, and sound levels on a website with the help of jQuery

My client has a new requirement: adding functionality to increase font size, adjust contrast/brightness, and control sound on his website. When clicking on any of the control images, a slider should appear for the user to make adjustments accordingly. Ho ...

Issue with the select element in Material UI v1

I could really use some assistance =) Currently, I'm utilizing Material UI V1 beta to populate data into a DropDown menu. The WS (Web Service) I have implemented seems to be functioning correctly as I can see the first option from my Web Service in t ...

Failed submission: XMLHttpRequest and FormData not processing data correctly

I'm attempting to use AJAX to submit a form using the post method along with a FormData object. Here's a simplified version of the JavaScript code: var form=…; // form element var url=…; // action form['update'].onclick=function ...

Is there a way to efficiently line up and run several promises simultaneously while using just one callback function?

I am currently utilizing the http request library called got. This package makes handling asynchronous http connections fast and easy. However, I have encountered a challenge with got being a promisified package, which presents certain difficulties for me ...

Is there a way to convert inline styling to CSS using Material-ui within a React component?

In my development work with React, I initially utilized inline styling to customize the appearance of material-UI components. However, I have come to realize that utilizing CSS provides a more structured and efficient approach to styling components. Despit ...

It's essential to ensure that this property remains responsive, whether through the data option or by initializing the property for class-based components

This code snippet contains the template and path information. <template> <div class=""> <c1 :text="message1"></c1> <c1 :text="message2"></c1> </div> </templa ...

Converting an Array with Key-Value pairs to a JSON object using JavaScript

After using JSON.stringify() on an array in JavaScript, the resulting data appears as follows: [ { "typeOfLoan":"Home" }, { "typeOfResidency":"Primary" }, { "downPayment":"5%" }, { "stage":"Just Looki ...

The absence of essential DOM types in a TypeScript project is causing issues

Recently, I've been working on setting up a web app in TypeScript but I seem to be missing some essential types that are required. Every time I compile using npm run build, it keeps throwing errors like: Error TS2304: Cannot find name 'HTMLEleme ...

Printing an Iframe using Safari print with Javascript results in an empty output

After researching the issue of printing blanks in Safari, I discovered that a white flash occurs before the print dialog can grab the content of the iframe. All my javascript works perfectly in every browser except for Safari. When attempting to print, it ...

How come I am able to send back several elements in react without the need to enclose them in a fragment

This piece of code is functioning properly in React, displaying all the names on the page. However, I am questioning why it is returning multiple elements as a React component. Shouldn't they be wrapped in a single fragment? function App() { const n ...

What is the best way to delete a nested child object using a specific identification number?

Here is the current json structure: $scope.dataList = [{ CompanyName: null, Location: null, Client: [{ ClientId: 0, ClientName: null, Projects:{ Id: 0, Name: null, } }] }]; I'm attempting to remo ...

What is the best way to retain selection while clicking on another item using jQuery?

There is a specific issue I am facing with text selection on the page. When I apply this code snippet, the selected text does not get de-selected even after clicking .container: jQuery('.container').on("mousedown", function(){ jQuery('. ...

Applying box shadow to input group addon in Bootstrap 3 using CSS

What I am trying to achieve is that when I click on the inputbox or selectbox, the box shadow defined in my CSS should also cover the input-group-add-on feature in Bootstrap 3. The issue I'm facing is that the input-group-add-on does not display the ...

The strict mode in React reveals unexpected changes in state with double rendering

While working with React, I've noticed that it renders twice in Strict mode during development to ensure the function remains pure without any side effects. However, I'm facing some inconsistency in retrieving the state in my case. It seems like ...

After the checkbox is clicked, I must send a boolean value to the function through the input flag in AngularJS

<input class="bx--toggle" id="toggle-view" type="checkbox" ng-model="vm.monthView" ng-change="vm.getRelevantData()" ng-attr-data-modal-target="{{vm.alertForSaveAll ? '#add-save-all-alert-modal': 'undefined'}}"> Within this p ...

Enhance jQuery event handling by adding a new event handler to an existing click event

I have a pre-defined click event that I need to add another handler to. Is it possible to append an additional event handler without modifying the existing code? Can I simply attach another event handler to the current click event? This is how the click ...

Order Up: Vue Draggable Next feature keeps your lists in line

I need to maintain the order of two lists in local storage so that their positions are saved and retrieved between sessions. In my Vue 3 TS project, I am utilizing this library. Check out the code snippet below: <template> <div> <h3> ...

Resolving DataTables Error

Here is my JavaScript code snippet. <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css"> <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/buttons/1.2.1/css/but ...

Tips for choosing option values from the browser console in Angular

Is there a way to choose one of the list values directly from the browser console? I appreciate any assistance provided <select style="width: 100%" id="Select1" class="css-dropdowns ng-not-empty ng-dirty ng-valid ng-valid-required n ...