How to Share Local Storage | Session Storage between different domains | With Demo

 Here You can check how to share domain with Local Storage and Session Storage hare data between multiple domains (for example an auth token) can be somehow hard as we all know that all browser side data storage APIs (Localstorage, cookies etc.) are related to one specific domain.

    


Implementation:

1- Create a listener in the iframe that saves the data passed in localStorage

2- Create a listener in the iframe that sends the data back

3- Using postMessage, we invoke the iframe’s saving function from the parent

4- in whatever other domain we ask for the data from the iframe (using postMessage and listening for a response).

Iframe code

Listen to a message event, check the type of action (save or get) if save, it adds an item to LocalStorage, if get: return the data using postMessage

const domains = [
"https://www.domain1.com",
"https://www.domaine2.com"
]
window.addEventListener("message", messageHandler, false);function messageHandler(event) {
if (!domains.includes(event.origin))
return;
const { action, key, value } = event.data
if (action == 'save'){
window.localStorage.setItem(key, JSON.stringify(value))
} else if (action == 'get') {
event.source.postMessage({
action: 'returnData',
key,
JSON.parse(window.localStorage.getItem(key))
}, '*')
}
}

One of the other windows code will save a data

Uses postMessage to send a message event to the iframe.

const data = doSomeThingToGetData()
const iframe = iframe = document.getElementById('iframe-id')
iframe.contentWindow.postMessage({
action: 'save',
key: 'keyForData',
value: data
})

And now any time one of the windows wants to get this data

Send a message event and the listen to a message event that the iframe will send back.

const iframe = iframe = document.getElementById('iframe-id')
iframe.contentWindow.postMessage({
action: 'get',
key: 'keyForData'
})
window.addEventListener("message", messageHandler, false);function messageHandler(event) {
const { action, key, value } = event.data
if (action == 'returnData'){
useData(key, value)
}
}

Angular 13 Reactive Form Validation

 

Demo URL




Angular 13 Reactive Form Validation With Demo

 

Demo URL

Register Form Angular

How to add static text inside an input form


 


How to add static text inside an input form

  



What is Window: pagehide event in Javascript

 Here You can use Easy way pagehide.  The pagehide event is sent to a Window when the browser hides the current page in the process of presenting a different page from the session's history.

For example, when the user clicks the browser's Back button, the current page receives a pagehide event before the previous page is shown.


  1. A mobile user visits your page.
  2. The user then switches to a different app.
  3. Later, the user closes the browser from the app manager.

Examples

In this example, an event handler is established to watch for pagehide events and to perform special handling if the page is being persisted for possible reuse.

window.addEventListener("pagehide", event => {
  if (event.persisted) {
    /* the page isn't being discarded, so it can be reused later */
  }
}, false)

hookwebpackerror transform failed with 1 error error invalid version 15.2 15.3

Go to .browserslistrc and remove safari problem will be resolved 


last 1 Chrome version

last 1 Firefox version

last 2 Edge major versions

last 2 Safari major versions --- Remove this 

last 2 iOS major versions

Firefox ESR

not IE 11 # Angular supports IE 11 only as an opt-in. To opt-in, remove the 'not' prefix on this line.


What is Array of Object in JavaScript?

 In This Article I will be show how to Array of Object Array  in JavaScript. 

Here Below Simple Object

{

 firstname:"Vijay",

lastname:"Chauhan",

type:"admin",

id:1

}

This Object represent a Registration There can be many types name  each object specific of Registration.




What is Destructuring in JavaScript

 The destructuring  is a JavaScript expression that makes it possible to unpack values from arrays, or properties from objects, into distinct variables.

Demo URL



Syntax : let a, b, rest;

[a, b] = [10, 20];


console.log(a);

// expected output: 10


console.log(b);

// expected output: 20


[a, b, ...rest] = [10, 20, 30, 40, 50];


console.log(rest);

// expected output: Array [30,40,50]


What is literal in javascript

literal Syntax:

{foo:'Vijay'}

JavaScript Literals are constant values that can be assigned to the variables that are called literals or constants. JavaScript Literals are syntactic representations for different types of data like numeric, string, Boolean, array, etc data. ... The literal “Vijay” represents, the value Vijay for the variable name.

Javascript Class 2 Arrow Functions

 An arrow function expression is a compact alternative to a traditional function expression, but is limited and can't be used in all situations.





Javascript Class 1 Arrays

JavaScript Arrays sing an array literal is the easiest way to create a JavaScript Array. Syntax: const array_name = [item1, item2, ...];.








What is JavaScript?

JavaScript is a scripting language that enables you to create dynamically updating content, control multimedia, animate images, and pretty much everything else. (Okay, not everything, but it is amazing what you can achieve with a few lines of JavaScript code.)




Best Practices Security of codes , Breaches Attack | SSR | Angular

 Security Code

1. Preventing cross-site scripting (XSS)

The injection of scripts into DOM elements is a very common occurrence to damage or steal the website data, such as:


1.Authentication details

2.Credentials

3.Payment data

4.Social Security numbers

5.Web tokens

2. HTTP-related Vulnerabilities

Cross-site request forgery (CSRF) and cross-site script inclusion are the most common HTTP vulnerabilities that can affect any Angular application, though Angular has created in-build assistants that prevent them from the client side. 

    Angular’s cross-site scripting security model

Sanitization and security contexts

Angular defines the following security contexts:


HTML is used when interpreting a value as HTML, for example, when binding to innerHtml.

Style is used when binding CSS into the style property.

URL is used for URL properties, such as <a href>.

Resource URL is a URL that is loaded and executed as code, for example, in <script src>.

Direct use of the DOM APIs and explicit sanitization calls

    Trusting safe values

To mark a value as trusted, inject DomSanitizer and call one of the following methods:

We need to make a service for BypassUrl

bypassSecurityTrustHtml

bypassSecurityTrustScript

bypassSecurityTrustStyle

bypassSecurityTrustUrl

bypassSecurityTrustResourceUrl

Server-side XSS protection

Avoid risky Angular APIs


The “Angular way” safeguards you from XSS

1.Use innerHTML with caution

2.Never use templates generated by concatenating user input

3.Never use native DOM APIs to interact with HTML elements

4.Avoid template engines on server-side templates

5.Scan your Angular project for components which introduce security vulnerabilities


SSR

1.Facilitate web crawlers through search engine optimization (SEO)

    2.Improve performance on mobile and low-powered devices

    3.Show the first page quickly with a first-contentful paint (FCP)

Data breaches Security

1. PASSWORD ATTACK

2. PHISHING AND SPEAR PHISHING 

3. EAVESDROP ATTACK

4. CROSS-SITE SCRIPTING ATTACK

Angular Template Syntax | Demo | Example

 More on template syntax

You might also be interested in the following:

  • Interpolation—learn how to use interpolation and expressions in HTML.
  • Template statements—respond to events in your templates.
  • Binding syntax—use binding to coordinate values in your application.
  • Property binding—set properties of target elements or directive @Input() decorators.
  • Attribute, class, and style bindings—set the value of attributes, classes, and styles.
  • Event binding—listen for events and your HTML.
  • Two-way binding—share data between a class and its template.
  • Built-in directives—listen to and modify the behavior and layout of HTML.
  • Template reference variables—use special variables to reference a DOM element within a template.
  • Inputs and Outputs—share data between the parent context and child directives or components
  • Template expression operators—learn about the pipe operator, |, and protect against null or undefined values in your HTML.
  • SVG in templates—dynamically generate interactive graphics

How to use splice Method In Angular

Splice method is changes the content of an Array  Which can help the Adding new element and also can removing odd Element.

Parameters of Details

Index: Index which of changing of the Array

HomMany: In Integer How many number in odds elements of array and removed if the 0 numbers in array can removed 

Ele: The Element can add of array which can add odd element 


The Syntax  Of Splice Method 

Array.splice(index, howmany, [ele1, ele2, ....eleN ])

Demo Url



 arr = ["orange""mango""banana""sugar""tea"];

How to show student info – name and roll number with Mysql

 In this tutorial, we will learn the followings;

  1. PHP program to show the student information.
  2. PHP program to show the student information with form values entered by the user.
  3. PHP program to show the student information with a database

Step 1 : 

<html>
<h2>T4Tutorials.com</h2>
<h3>simple programm</h3>
<p>show output student name and roll number</p>
 
</html>
 
<?php
class student
{
    public $name= 'ali';
public $rno=55;
}
$a = new student();
echo $a->name;
echo "<br>";
echo $a->rno;
echo "<br>";
$b = new student ();
echo $b->name;
echo "<br>";
echo $b->rno;
?>


Step 2 : 

<html>
<h2>T4Tutorials.com</h2>
<h3>Form program</h3>
<p>show output student name and roll number</p>
</html>
<html>
<body>
<form method="post">
<p>Enter Name</p>
<input type="text" name="name" />
<p>Enter Roll number</p>
<input type="text" name="number" />
<input type="submit" name="submit" />
</form>
<?php
class student
{
    public $name= 'ali';
public $rno=77;
}
$a = new student();
if(isset($_POST['submit'])){
$a->name=$_POST['name'];
$a->rno=$_POST['number'];
echo"Name of student= $a->name</h2><br>";
echo"Roll number of student= $a->rno</h2>";
}
?>

Step 3 :

<html>
<head>
<style>
div {
align:center;
width:400px;
height:300px;
border: solid black;
background-color:orange;
 
padding: 20px;
}
 
</style>
</head>
<body>
<div>
<h1>Enter data for Student</h1>
<form  method="post">
Name:<br />
<input type="text" name="name"/><br />
Roll number:<br />
<input type="text" name="rno"/>
<br><br>
<input type="submit" name="OK" />
</form>
<?php  
$con=mysqli_connect("localhost","root","","student");
if(isset($_POST['OK'])){
$p =$_POST['name'];
$f =$_POST['rno'];  
$sql=mysqli_query($con,"INSERT INTO students (name,rno) VALUES ('$p','$f')");
}
?>
</div>
</body>
 
</html>

How to Generate an AST in C++

Solution

 I'm going to go against conventional wisdom here and say that you should build your AST manually with natural language-specific data-structures.

A generic "AST data structure" will be too general to work with comfortably -- the code that consumes the AST to do anything useful with it will be obscured by the workarounds to access the data it wants. If you go this route (or use a parser generator), you'll likely end up building a translation layer to go from the generic structure to an AST that actually makes sense for your language. Why not avoid the middleman and build the final data structure directly?

I suggest writing a first syntactic pass that consumes the tokens it needs for each possible construct (probably peeking ahead one token as needed). This syntactic pass would construct the AST out of linked instances of data structures that represent each possible construct in your language. For example, if your program can consist of a series of statements, where each statement can be either a function declaration or a function call, you could create the following data structures:

AST (struct)
    -> std::vector<Statement*> statements

StatementKind (enum class)
    -> Function
    -> Call

Statement (struct)
    -> StatementKind kind

Function : Statement (struct)
    -> std::string name
    -> std::vector<Statement*> body

Call : Statement (struct)
    -> std::string name
    -> Function* called

Then the syntactic pass to build the initial AST might look like:

auto ast = parseAST();

where parseAST calls parseStatement repeatedly, which consumes and/or peeks at tokens to determine whether the statement is a function definition or a function call, then calls parseFunction or parseCall appropriately. This is called a hand-written recursive descent parser, and is in my experience by far the simplest and best type of parser you can write. Yes there is boilerplate to write, but it's also very clear and flexible code.

The syntactic phase generates syntax error messages as it goes, attempting to recover as best as it can when an error is found (this is one argument for semicolon-delimited languages -- the compilers and tools can often recover from errors much more easily, since it often suffices to skip to the next semicolon when an error is encountered before trying to parse the next construct).

If a function is allowed to be called before it is defined, this is simple to handle too -- just parse the call part without checking if a function with that name exists at the time you first parse it, then correlate it later.

A second, semantic, pass through the AST would annotate it with any missing cross-referenced data (e.g. resolving function calls' function names with those functions' definitions, or generating an error if the name is not found). Once that's done, you have a full AST that's guaranteed to represent a valid program (since you did all the semantic error checking in this pass), and can have optimizations applied to it, followed by the code generation phase (and more optimizations along the way).

Note that I completely left out any mention of LL or LR parsers, etc. The theoretical notation and categorization of your language is important (as it can prove it's non-ambiguous, for example), but from an implementation point of view, it's far more important to have clean, easily understood and above all easily modifiable code than to adhere to a specific parsing mechanism. Examples of other compilers that use hand-written parsers include GCC, Clang, and Google's V8, among others.

In terms of efficiency, the AST is generally iterated over several times after it's constructed, and needs to stick around in memory until late in the process (possibly right until the end, depending on how you do your code generation), and so it's best to use an object pool to allocate the records for your AST than to dynamically allocate everything separately on the heap. Finally, in place of strings, it's generally better to use an offset-and-length into the original source code.

SQL Server — Core Concepts with examples

  Data Definition Language (DDL) : CREATE , ALTER , DROP (tables, views, procedures, triggers). Data Manipulation Language (DML) : SELECT ,...

Best for you