File uploading and reading in angular

I have file upload control which holds the selected file as below,

<div class="Block">
  <label id="lbl">File </label>
  <input #fileInput type='file'/>
</div>

I have a submit button as below,

<button type="button" class="btn btn-primary" 
     (click)="uploadDocument()">Upload File</button>

When I select a file and click on the upload button the file I need the contents inside the file without sending it to the server and reading from there and showing content of file in table format.

Note: Type of file will be txt

I have to do this without api

Why my animation frame is speeding at the end when using a condition?

I would like to build a simple game with UFOs that crosses the window and that can be the target for a tank. Below is the code to create a UFO crossing the window screen. I am using a class for that and set temporary hard coded conditions to keep animation frame working only when UFO is within the screen range. However with this condition at the end of the animation the UFO suddenly speeds up.


class flying_ufo {
    
    constructor(name) {
        this.name = name;
        this.ufo = document.querySelector('.ufo');
        this.angle = 0;
        this.x = 0;
        this.y = 0;
        this.rotate = 0;
        this.start = undefined;
        this.lastTimestamp = undefined;
        this.animate = this.animate.bind(this);
        this.scale = window.innerWidth / 50;
    }

   
animate(timestamp) {
    if (this.start === undefined) {
        this.start = timestamp;
        this.lastTimestamp = timestamp;
    }

    const delta = (timestamp - this.lastTimestamp) / 1000;
    this.lastTimestamp = timestamp;

    const speedX = 100; 
    const speedY = 20;

    this.x += speedX * delta;
    this.y -= speedY * delta;

    this.degreeValue = window.innerWidth > 900 ? 0.002 : 0.02;
    this.rotate -= ((window.innerWidth) * delta) * this.degreeValue;

    this.ufo.style.transform = `translate(${this.x}px, ${this.y / 2}px) rotate(${this.rotate}deg)`;

    const isInView = this.x <= window.innerWidth &&
                   this.x >= 0 &&
                   this.y / 2 < window.innerHeight / 2 &&
                   this.y / 2 + window.innerHeight > 0;


    // if (isInView) {
        requestAnimationFrame(this.animate);
    // }
}

    init_ufo() {

        requestAnimationFrame(this.animate);
    }

}



const my_ufo = new flying_ufo('name1');
my_ufo.init_ufo();

<body>
    <div class="ufo"><img src="ufo.png" alt="" width="100%"></div>
</body>

  html, body{
    position: relative;
    margin: 0; padding: 0; height: 100%;
    background: radial-gradient(circle at center, #1c1c3c, #0b0b16);
    overflow: hidden;
  }

  
  .ufo {
    width: 110px;
    position: absolute;
    top: 50%;
    filter: drop-shadow(0 0 15px #6cf3ff);
    transition: transform 0.3s ease-in-out;
    will-change: transform;
  }

If I remove the isInView condition it then moves smoothly and regularly. Can’t figure it out why? Can somebody explains why this is happening?

Issue with Recharts label (React.JS)

Faced an issue implementing text underline in the Recharts library, specifically in a Pie Chart. It should look like this:enter image description here

Here’s how it turns out for me:
enter image description here

CodeSandbox:
https://codesandbox.io/p/devbox/delicate-sun-lnvqkg?file=%2Fsrc%2Fstyles.css&workspaceId=ws_QyKMbtfzZ89mpAdWxtqWKL

Is it possible to make it look like in the first screenshot, so that the dashed line starts from the column and goes under the text? I would appreciate any help.

“Cloud Identity Groups” Advanced Service Missing in Apps Script “Services” List?

This page:

https://developers.google.com/apps-script/advanced/groups

says that there is an Advanced Service for Cloud Identity Groups that can be enabled, but my list of Services has no such option in the list. I am a Superadmin in a domain that has Groups for Business enabled. What am I missing?

* AdSense Management APIDocumentation
* Admin SDK API
* Analyticsreporting
* Area120 Tables API
* BigQuery API
* Campaign Manager 360 API
* Content API for Shopping
* Drive API
* Drive Activity API
* Drive Labels API
* Enterprise License Manager API
* Gmail API
* Google Analytics API
* Google Analytics Admin API
* Google Analytics Data API
* Google Calendar API
* Google Chat API
* Google Classroom API
* Google Docs API
* Google Sheets API
* Google Slides API
* Google Tasks API
* Google Workspace Events API
* Google Workspace Reseller API
* Groups Migration API
* Groups Settings API
* Merchant API
* Peopleapi
* Tag Manager API
* YouTube Analytics API
* YouTube Data API v3
* YoutubePartner

List of "Advanced Services" available to install in a new Apps Script project

Customizing button for save PDF

I want to use customize button to save my table to PDF and also hide the ‘PDF’ word which comes as default to save the pdf on top of data table. i want to use only the customized button

but my below code is not working.

<script>
   $(document).ready(function () {
  var table = $('#example').DataTable({
    "bLengthChange": false,
    "bFilter": false,
    "bInfo": false,
    "pagingType": "simple",
    "lengthMenu": [15, 25, 50, -1],
    "paging": true,
    "paging.numbers": true,
    "ordering": false,
    dom: 'Bfrtip',
  buttons: ['pdfHtml5']
    });
    table.button( '.buttons-pdfHtml5' ).css('display', 'none');
     $("#btn").on("click", function() {
    table.button( '.buttons-pdfHtml5' ).trigger();
});
});
</script>

<button type="button" id="btn">save pdf</button>

Making a ChatApp Two – Way

So, basically, I have created a basic chat app using html, css, and javascript. I am also using SocketIO, so that I can make the chat app real-time. The problem is, I am not able to figure out how I can make this chat app two – way, Ie, a user can only connect with one other user. Right now, everyone can connect with each other.
Here is the sample html code and the javascript code. :

NOTE: I am running this with node server.js to run my program. :

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel = "stylesheet" type = "text/css" href = "style.css"/>
</head>
<body>
    <div class="app">
        <div class="screen join-screen active">
            <div class="form">
                <h2>Join Chatroom</h2>
                <div class="form-input">
                    <label>Username</label>
                    <input type = "text" id = "username"/>
                </div>
                <div class="form-input">
                    <button id="join-user">Join</button>
                </div>
            </div>
        </div>
        <div class="screen chat-screen">
            <div class="header">
                <div class="logo">Chatroom</div>
                <button id = "exit-chat">Exit</button>
            </div>
            <div class="messages">
                <!--all of the message will appear here!-->
            </div>
            <div class="typebox">
                <input type = "text" id = "message-input"/>
                <button id="send-message">Send</button>
            </div>
        </div>
    </div>
    <script type = "text/javascript" src = "socket.io/socket.io.js"></script>
    <script type = "text/javascript" src="code.js"></script>
</body>
</html>
(function() {
    const app = document.querySelector(".app");
    const socket = io();

    let uname;

    app.querySelector(".join-screen #join-user").addEventListener("click", function() {
        let username = app.querySelector(".join-screen #username").value;
        if (username.length == 0) {
            return;
        }
        socket.emit("newuser", username);
        uname = username;
        app.querySelector(".join-screen").classList.remove("active");
        app.querySelector(".chat-screen").classList.add("active");
    });
    app.querySelector(".chat-screen #send-message").addEventListener("click", function() {
        let message = app.querySelector(".chat-screen #message-input").value;
        if (message.length == 0) {
            return;
        }
        renderMessage("my", {
            username:uname,
            text:message
        })
        socket.emit("chat", {
            username:uname,
            text:message
        })
        app.querySelector(".chat-screen #message-input").value = "";
    });
    app.querySelector(".chat-screen #exit-chat").addEventListener("click", function() {
        socket.emit("exituser", uname);
        window.location.href = window.location.href;
    })
    socket.on("update",function(update) {
        renderMessage("update", update);
    })
    socket.on("chat",function(message) {
        renderMessage("other", message);
    })
    function renderMessage(type,message) {
        let messageContainer = app.querySelector(".chat-screen .messages");
        console.log(type)
        if (type == "my") {
            let el = document.createElement("div");
            el.setAttribute("class","message my-message");
            el.innerHTML = `<div>
                                <div class = "name">You</div>
                                <div class = "text">${message.text}</div>
                            </div>`;
            messageContainer.appendChild(el);
        } else if (type == "other") {
            let el = document.createElement("div");
            el.setAttribute("class","message other-message");
            el.innerHTML = `<div>
                                <div class = "name">${message.username}</div>
                                <div class = "text">${message.text}</div>
                            </div>`;
            messageContainer.appendChild(el);
        } else if (type == "update") {
            let el = document.createElement("div");
            el.setAttribute("class","update");
            el.innerHTML = message;
            messageContainer.appendChild(el);
        }
        //scroll the chat to the end.
        messageContainer.scrollTop = messageContainer.scrollHeight - messageContainer.clientHeight;
    };
})();

I appreciate any pointers and/or tips you may give.

Honestly, I do not have that much internet knowledge, so, I was pretty clueless on how to go about this.

Optional class property for object

I want to be able to define objects as:

/**@type{CheckData}**/
object1 = {check:true}
/**@type{CheckData}**/
object2 = {check:false, data: 'Why?'} 

While I can use this @typedef with success:

/**
 * @typedef {Object} CheckData
 * @property {boolean} check
 * @property {*=} data
 */

I have the following class:

/**
 * @class CheckData
 * @property {boolean} check - Indicates if the operation was successful.
 * @property {*=} [data] - Optional data associated with the status.
 */
export class CheckData {
    /**
     * Creates an instance of CheckData.
     * @param {boolean} check - Whether the operation is considered successful.
     * @param {*=} [data] - Optional data. 
     */
    constructor(check, data) {
        this.check = check;
        if (data !== undefined) { 
            this.data = data;
        }
    }
}

This class type works fine for object2 = {check:false, data: 'Why?'}, but it fails for object1 = {check:true}, despite data being a optional property:

Property 'data' is missing in type '{ check: true; }' but required in type 'CheckData'

Yet if I use @typedef, it works fine.

How can I define data to be an optional property in CheckData class?

html2canvas and jsPDF not rendering lightning combobox values in LWR app

We have a web app running in LWR using LWC and Node.js as backend.

We want to implement a “export as PDF” functionality for every of our pages. After some time of research I decided to use a combination of html2canvas + jsPDF to do this and it works perfect! Except for some base lightning-combobox components we use for some selectors.

The combobox itself is exported correctly (the container and icon with correct colors) but the text inside the combobox is not displayed (the values / placeholders). This is very important because those values are information we want in the PDF so I need this resolved.

The code for the export:

async function exportToPDF(content, filename = 'export.pdf', canvasOptions, pdfOptions) {

    const canvas = await html2canvas(content, canvasOptions || {
        scale: 2,  // improves quality
        useCORS: true  // enable if you load images from other domains
    });

    const imgData = canvas.toDataURL('image/png');
    const pdf = new jsPDF(pdfOptions || {
        orientation: 'portrait',
        unit: 'px',
        format: [canvas.width, canvas.height]
    });

    pdf.addImage(imgData, 'PNG', 0, 0, canvas.width, canvas.height);
    pdf.save(filename);
}

Screenshot of one of our pages:
page

Screenshot of resulting PDF

pdf

Is there something I can do here? I understand this maybe has something to do with Shadow DOM protecting the component inside.. Is there a workaround?

How can i keep this div visible until it moves to its end position but scroll past it after it has moved to its end position?

I am able to make this div move right when scrolling but i want its position to be fixed while scrolling before it has reached its end position. The problem I am having is that when I scroll further after the movingDiv has reached its end position, the position continues to remain fixed.

const container = document.querySelector(".container");
const movingDiv = document.querySelector(".moving-div");
let scrollPosition = 0;
let endPosition = 0;

window.addEventListener("scroll", () => {
  let scrollPosition = window.scrollY;

  movingDiv.style.transform = scrollPosition <= endPosition ?
    `translateX(${scrollPosition}px)` :
    `translate(300px)`;

  // Stop movement when movingDiv reaches maxPosition

  if (movingDiv.offsetLeft >= movingDiv.maxPosition) {
    movingDiv.style.position = "absolute";
  } else {
    movingDiv.style.position = "fixed";
  }
});
.container {
  height: 200vh;
}

.moving-div {
  height: 100px;
  width: 100px;
  background-color: black;
  left: 0;
  transition: 0.3s right ease;
}
<div class="container">
  <div class="moving-div"></div>
</div>

Goole maps api polyline label

my project

my project
I want to add

I want to add

I want to show the routes, distances and times between two regions on Google API. I combined the two examples and made it the current one, but when I click on the routes, I cannot show the distance, time or the route it is.

var directionDisplay;
var directionsRenderers = [];
var directionsService = new google.maps.DirectionsService();
var map;

function drawMap(midpoint) {
    var mid = midpoint.split(",");
    var start = new google.maps.LatLng(mid[0], mid[1]);
    var myOptions = {
        zoom: 7,
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        center: start,
        mapTypeControl: false
    };
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
}

function getRendererOptions(main_route) {
    var _colour;
    var _strokeWeight;
    var _strokeOpacity;
    var _suppressMarkers;
    var _label;
    if (main_route) {
        _colour = '#00458E';
        _strokeWeight = 4;
        _strokeOpacity = 1.0;
        _suppressMarkers = false;
    } else {
        _colour = '#ED1C24';
        _strokeWeight = 4;
        _strokeOpacity = 0.4;
        _suppressMarkers = false;
    }

    var polylineOptions = {
        strokeColor: _colour,
        strokeWeight: _strokeWeight,
        strokeOpacity: _strokeOpacity
        
    };

    var rendererOptions = {
        draggable: false,
        suppressMarkers: _suppressMarkers,
        polylineOptions: polylineOptions
    };

    return rendererOptions;
}

function renderDirections(result, rendererOptions, routeToDisplay) {
    var _colour;
    var _strokeWeight;
    var _strokeOpacity;
    var _suppressMarkers;

    if (routeToDisplay === 0) {
        _colour = '#00458E';
        _strokeWeight = 6;
        _strokeOpacity = 1.0;
        _suppressMarkers = false;
    } else {
        _colour = '#ED1C24';
        _strokeWeight = 4;
        _strokeOpacity = 0.4;
        _suppressMarkers = false;
    }

    // create new renderer object
    var directionsRenderer = new google.maps.DirectionsRenderer({
        draggable: false,
        suppressMarkers: _suppressMarkers,
        polylineOptions: {
            strokeColor: _colour,
            strokeWeight: _strokeWeight,
            strokeOpacity: _strokeOpacity
            
        }
    });
    directionsRenderer.setMap(map);
    directionsRenderer.setDirections(result);
    directionsRenderer.setRouteIndex(routeToDisplay);
    directionsRenderers.push(directionsRenderer);

}

function requestDirections(start, end, routeToDisplay, main_route) {
    for (var i = 0; i < directionsRenderers.length; i++) {
        directionsRenderers[i].setMap(null);
    }
    directionsRenderers = [];

    var request = {
        origin: start,
        destination: end,
        travelMode: google.maps.DirectionsTravelMode.DRIVING,
        provideRouteAlternatives: main_route
    };

    directionsService.route(request, function (result, status) {

             
        var rendererOptions;
        if (status == google.maps.DirectionsStatus.OK) {
            if (main_route) {
                rendererOptions = getRendererOptions(true);
                for (var i = 0; i < result.routes.length; i++) {
                    renderDirections(result, rendererOptions, i);
                }
            } else {
                rendererOptions = getRendererOptions(false);
                renderDirections(result, rendererOptions, routeToDisplay);
            }   
                document.getElementById('msg').innerHTML = "";
                for (var i = 0; i < result.routes.length; i++) {
                    var directionsData = result.routes[i].legs[0]; // Get data about the mapped route
                    if (!directionsData) {
                      window.alert('Yol tarifi isteği başarısız oldu');
                      return;
                    }
                    else {
                      if(i==0){ color = '#00458E';} else{ color = '#ED1C24';}
                      document.getElementById('msg').innerHTML += " <font color='" + color + "'> Mesafe " + directionsData.distance.text + " (" + directionsData.duration.text + ").</font/></br>";
                    }
                }
        }   
    
    });
}




// users route
requestDirections('(Letchworth)', '(Crawley)', 0, true);
drawMap("türkiye");
    html, body, #map_canvas {
    height: 90%;
    width: 100%;
    margin: 0px;
    padding: 0px
}
<!DOCTYPE html>
<html>

<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>JSFiddle uLu7w814</title>

  <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyA5dMMFQXt4os3Ndk0gMu8sGOHqGYv4_VU&libraries=geometry,places&ext=.js"></script>
</head>
<body>
  <label>Start</label>&nbsp;
<input id="start" size="50" value="Letchworth" />
<br />
<label>End</label>&nbsp;&nbsp;
<input id="end" size="50" value="Crawley" />
<input type="button" value="post directions" id="btn" onclick="requestDirections(document.getElementById('start').value, document.getElementById('end').value,0,true);" />
<div id="msg"></div>
<div id="map_canvas"></div>

</body>
</html>

I want to add information to polylines as in the 2nd image.

Input field’s old and new value are shown after changing the value with js [closed]

I have a weird situation where I change the value of a hidden input field from “2” to “3”.

Actual screen shot after change with js

At the first sight the new value “3” seems to be accepted and assigned to the attribute value.

But when I open the details information and scroll down to the attribute value, there is still the old value “2” standing.

enter image description here

When I select for the value (document.getElementById("rowid").value) then I get the old value “2”. Why is this so?

Vanilla JS Scroll Virtualization Causes Element Shuffling and Slow Performance Despite Throttling/requestAnimationFrame

I’m implementing a custom scroll virtualization for a testimonials section in Vanilla JS. When clicking “show more testimonials,” I add 10 more elements and collect all of them using querySelectorAll, then handle scroll events to remove items outside the viewport and replace them with empty div (we could see it despite using BUFFER if scroll too fast). However, this causes severe scroll lag and element shuffling.
gif file about mixing https://jmp.sh/s/o4xIAyjHp2QQ28gWG7K5
gif file about red empty div https://jmp.sh/s/PZl3lQUIp9u6TXlBJXjI

export function virtualize() {
const scroll = document.querySelector(".testimonial-container");
  const container = scroll.querySelector(".phantom-container");
  const ITEM_HEIGHT = 150;

  let allTestimonials = Array.from(container.querySelectorAll(".testimonial"));

  scroll.removeEventListener("scroll", virtualizeScroll);
  scroll.addEventListener("scroll", virtualizeScroll);

  let topEmptyDiv = scroll.querySelector(".empty-div--top");
  if (!topEmptyDiv) {
    topEmptyDiv = document.createElement("div");
    topEmptyDiv.classList.add("empty-div--top");
    topEmptyDiv.style.height = 0 + "px";
    topEmptyDiv.style.backgroundColor = "red";
    topEmptyDiv.style.width = "100%";
    topEmptyDiv.style.flexShrink = "0";

    scroll.prepend(topEmptyDiv);
  }

  

  let deletedTop = [];
  const BUFFER = 10;
  let rafId = null;
  function virtualizeScroll() {
    if (rafId) {
      cancelAnimationFrame(rafId);
    }
    let isAboveTop = 1;
    rafId = requestAnimationFrame(() => {
      toggleTopElements();
    });

    function toggleTopElements() {
      if (allTestimonials.length) {
        isAboveTop = ITEM_HEIGHT * BUFFER + allTestimonials[0].offsetTop < scroll.scrollTop;

        if (isAboveTop) {
          let element = allTestimonials.shift();

          deletedTop.unshift(element);
          element.remove();
          topEmptyDiv.style.height = `${parseInt(getComputedStyle(topEmptyDiv).height) + ITEM_HEIGHT}px`;
        }
      }
      let isBelowTop = scroll.scrollTop < topEmptyDiv.offsetHeight + ITEM_HEIGHT * BUFFER;
      if (isBelowTop && deletedTop.length) {
        let element = deletedTop.shift();

        allTestimonials.unshift(element);

        container.prepend(element);
        topEmptyDiv.style.height = `${parseInt(getComputedStyle(topEmptyDiv).height) - element.offsetHeight}px`;
      }
    }

local HTML slideshow display images when opened directly without a server

I’m building a local HTML slideshow for a wedding. It runs offline — I want to be able to double-click index.html and have it work without setting up a server.

The slideshow uses a SmugMug iframe and overlays a random image (from images/overlay/) every 30 minutes for 60 seconds. The overlay image doesn’t show — the screen just goes black during that time.

There are no JavaScript errors in the console, and I’ve double-checked my folder structure and image paths.

Folder structure

Wedding Show/
├── index.html
└── images/
    └── overlay/
        ├── welcome1.jpg
        ├── welcome2.jpg
        └── welcome3.jpg

Code

    <!-- File: index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  <title>Wedding Slideshow</title>
  <style>
    html, body {
      margin: 0; padding: 0; height: 100%; overflow: hidden; background: black;
    }
    #slideshowContainer {
      width: 100vw; height: 100vh; position: relative; background: black;
    }
    #onlineGallery {
      width: 100%; height: 100%; border: none;
      position: absolute; top: 0; left: 0; z-index: 1;
    }
    #googleDriveSlideshow {
      width: 100%; height: 100%;
      position: absolute; top: 0; left: 0; z-index: 2;
      display: none;
      background-size: contain;
      background-position: center;
      background-repeat: no-repeat;
      background-color: black;
    }
    #googleDriveIndicator {
      position: absolute; top: 20px; left: 20px; z-index: 4;
      background-color: rgba(255,255,255,0.8);
      color: #333; padding: 10px 15px;
      font-family: Arial, sans-serif; font-weight: bold;
      border-radius: 5px; display: none;
    }
  </style>
</head>
<body>
  <div id="slideshowContainer">
    <iframe id="onlineGallery"></iframe>
    <div id="googleDriveSlideshow"></div>
    <div id="googleDriveIndicator">Displaying Special Photo</div>
  </div>

  <script>
    const config = {
      baseSlideShowUrl: "https://gallery.captureeverymemory.com/frame/slideshow?key=bRFrVp&speed=10&transition=fade&autoStart=1&captions=0&navigation=0&playButton=0&randomize=0&transitionSpeed=2",
      localOverlayImages: ['welcome1.jpg', 'welcome2.jpg', 'welcome3.jpg'],
      localOverlayPath: 'images/overlay/',
      localPhotoDisplayTime: 60000,
      localPhotoSelectionInterval: 1800000,
    };

    const state = {
      shownLocalPhotos: new Set(),
      isOverlayVisible: false,
    };

    function getRandomLocalPhoto() {
      const unused = config.localOverlayImages.filter(img => !state.shownLocalPhotos.has(img));
      if (unused.length === 0) state.shownLocalPhotos.clear();
      const list = unused.length ? unused : config.localOverlayImages;
      const img = list[Math.floor(Math.random() * list.length)];
      state.shownLocalPhotos.add(img);
      return img;
    }

    function displayLocalOverlayPhoto() {
      const overlay = document.getElementById('googleDriveSlideshow');
      const gallery = document.getElementById('onlineGallery');
      const indicator = document.getElementById('googleDriveIndicator');
      const img = getRandomLocalPhoto();

      overlay.style.backgroundImage = `url('${config.localOverlayPath}${img}')`;
      overlay.style.display = 'block';
      gallery.style.visibility = 'hidden';
      indicator.style.display = 'block';
      state.isOverlayVisible = true;

      setTimeout(() => {
        overlay.style.display = 'none';
        gallery.style.visibility = 'visible';
        indicator.style.display = 'none';
        state.isOverlayVisible = false;
      }, config.localPhotoDisplayTime);
    }

    function scheduleLocalOverlayDisplay() {
      setInterval(() => {
        if (!state.isOverlayVisible) displayLocalOverlayPhoto();
      }, config.localPhotoSelectionInterval);
      setTimeout(displayLocalOverlayPhoto, 10000); // initial display after 10 sec
    }

    function refreshSlideshow() {
      const frame = document.getElementById('onlineGallery');
      frame.src = config.baseSlideShowUrl + "&refresh=" + new Date().getTime();
    }

    function initialize() {
      refreshSlideshow();
      scheduleLocalOverlayDisplay();
    }

    window.onload = initialize;
  </script>
</body>
</html>

When I open index.html by double-clicking (file:// path), the slideshow works fine but the overlay image doesn’t show up — just a black screen.

Is there a way to get background-image: url(‘images/overlay/filename.jpg’) to work when running HTML from file://, or do I have to switch to or use a local server?

Any workaround to make this slideshow fully portable without needing localhost?

How to open mobile app from browser in ios

In one of my projects, when a user tries to access the site from a mobile device, I want to redirect them to the existing mobile application. If the app is not installed, I want to open the App Store or Play Store so the user can install it. If the app is already installed, it should open and the user should be able to continue from there.

When I run the following code, it successfully opens the app on Android if it’s installed. However, on iOS, it doesn’t open the app and I get the error: “Safari cannot open the page because the address is invalid.”

const el = document.createElement('a');
el.href = "myApplication://";
el.click();

The app IDs are the same for both iOS and Android.

What to pass instead of ‘this’ in react function components

I have a task to rewrite class component to function one in React. Here’s the method that bothers me

    openDictionary = async () => {
        const {
            special,
            sysColumnName,
            label,
            listLabel,
            sysColumnId,
            columnId,
        } = this.model;
        const {
            match,
            location,
            listValue,
        } = this.props;
        const width = window.screen.width * .7;
        const height = window.screen.height * .7;
        const top = 0;
        const left = 0;
        window.editReferenceField = this; // This line!
        ...
    };

So, the line I marked as ‘This line!’ sets to a global window object’s field editReferenceField a class instance, which is a component itself. Logging it into the console gives me a real instance with all its methods etc.
The project I work on is quite big, and there’re several places I could find where the window.editReferenceField is used to access the component’s methods (and there’re also many places which I couldn’t find, I’m positive with that, because the app is very dynamic and allows user to add logic via scripts).

So, the question is, is there a way to do something similar in the function components? Unfortunately, I can’t know for sure which methods/fields will be accessed, so I can’t just assign this editReferenceField to an object with chosen methods, I need to pass the whole thing.
I’ll appreciate any help, thanks!