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

Vue - Utilizing mapState in Vuex to display the contents of the first object within an array

I am trying to display the names array from the first object in players using mapState with Vuex. Currently, the objects in players are listed based on their titles, but I want to filter them based only on the names in the first object for the current page ...

Customizing upload directories in elfinder for dynamic path generation

In my CodeIgniter project, I am trying to configure elfinder to have a dynamic upload path for each unique ID. The folder structure I am working with is as follows: Below are my elfinder settings: $idce = $_GET['id_c']; $client_code = $this- ...

Using the ng-show directive in AngularJS allows you to pass elements in

Web Development <li ng-show="sample($event)" TestLi</li> JavaScript Functionality $scope.sample = function($event){ //$event is undefined //perform some action } I have experimented with passing the HTML element using ng-click, but I am curio ...

Language translation API specifically designed to convert text content excluding any HTML formatting

I have a dilemma with translating text content in an HTML file into multiple languages based on user input. To accomplish this, I am utilizing the Microsoft Translator AJAX interface. The structure of my HTML file looks something like this; <h1>< ...

Tips for overcoming a challenge with a promise of $q

Currently in my AngularJS project, I am utilizing $q for promises and feeling a bit overwhelmed with the usage. How can I resolve this promise-related issue? My goal is to either return the user when isLoggedInPromise() is triggered or provide a response ...

Issues with sending parameters in JQuery Ajax POST request

Currently, I am delving into Ajax and encountering some issues with sending requests from the client side. I have a jsp file located at "/web" on my local server to manage requests. Though unsure if this is the best approach or if it should be handled by ...

Can theme changes be carried over between different pages using Material UI?

I've encountered an issue with MUI 5.14.1 where I'm getting an error every time I attempt to save themes across pages using localStorage. Any suggestions on how to resolve this problem or recommendations on a different approach would be greatly a ...

Strategies for Pagination Button Reduction in Vue

I am facing an issue with my pagination component. It is designed to receive props such as `totalPages` and `currentPage` in order to render buttons that allow users to change the current page. However, when there are a large number of products, an excessi ...

Ways to ensure a <div> element adjusts its height based on inner content dimensions

When using buttons in a chatbot that have text which changes based on selected options, I've encountered an issue where the text length sometimes exceeds the button's space. I'm looking for a way to make the containing div automatically adj ...

Limiting jQuery searches to a specific region: Tips and tricks

If I have the code snippet below: <div class="foo"> <div> some text <div class="bar"> </div> </div> </div> <div class="foo"> <div> some text <div class="bar"> some text </div> </div> </ ...

creating and managing multiple redirect routes in vue.js application

const router = new VueRouter({ routes: [ {path: '*', redirect: '/'} } )} I have configured this as the default redirect route in my routes.js file. Now, I am wondering how I can set multiple redirect paths and trigger them ...

Discovering the value of an item when the editItem function is triggered in jsGrid

Within my jsGrid setup, I have invoked the editItem function in this manner: editItem: function(item) { var $row = this.rowByItem(item); if ($row.length) { console.log('$row: '+JSON ...

In React Router version 4, it is stated that each router is only allowed to have a single child element when using multiple routes

I'm currently working on implementing a sidebar alongside the main content area using react-router-dom. Instead of just rendering <Sidebar/> directly, I want to pass it the location prop due to another issue where clicking a <Link/> in the ...

Angular CORS problem when sending information to Google Forms

When submitting the data: Error Message: Unfortunately, an error occurred while trying to send the data. The XMLHttpRequest cannot load https://docs.google.com/forms/d/xxxxxxxxxxxxx/formResponse. The response to the preflight request did not pass the ac ...

Is it possible to access a sub property using a dot string in Vue 3?

Given a Vue 3 proxy object structure as shown below: <script> export default { name: "test", data() { return { users: [{ "id": 1, "name": "Leanne Graham", " ...

Navigating the process of transferring a function to a functional component within React

Hey there, I'm fairly new to using React and TypeScript and I am facing a small issue with moving a function from the file App.tsx to a functional component called WordAddingForm.tsx. Any help would be greatly appreciated! Let's start with my Ap ...

error in three.js occurs when attempting to load .obj files

I've been encountering issues with OBJ files that I've downloaded from the internet. All of these files render like this: View Obj File Pic I'm using the standard OBJLoader for rendering. var loader = new THREE.OBJLoader(); loader.load( ...

Creating Tailored Breakpoints with Bootstrap for a Unique Design

Currently, I am delving into the world of front-end web design and taking advantage of Bootstrap for creating a responsive layout. However, I have noticed that Bootstrap only offers 5 predefined breakpoints. I am curious to know if there is a way to cust ...

Steps for setting up type-graphql in your projectNeed help with

Trying to include this in my TypeScript project: import { ID } from "type-graphql"; Encountered an issue when attempting to install type-graphql. Received a 404 error stating that it could not be found in the npm registry. npm install @types/type-graphq ...

Limit the selection to just one element in a v-for loop in VueJS

I am utilizing Vue v2 My goal is to change only the properties of the selected element. Specifically, when the response is marked after clicking, it should switch to red color with a text that reads 'Unmark'. Conversely, if the button is clicked ...