Check if a url is already open in JavaScript |
X

Congrats, You are Subscribed to Receive Updates.

Check if a url is already open in JavaScript


Introduction

From the string side functions, we have to do many string manipulation programs. Some cases we need to identify whether the string contains another string or now.  PHP String Contains Specific Word is also called as strpos. This function helps to find the string in another string. or a charater in a string or a sentence. Strpos is a quite easy program to compare string and get its position. Lets go with examples.

Example 1

This is just finding the string from another string.

<?php 
$first = " This is first string to find the first word and replace the first with second";
if(strpos($first, 'first') !== false){
  // Here you can write the program of string exist in it. 
} ?>

<script type="text/javascript">
        // Broad cast that your're opening a page.
        localStorage.openpages = Date.now();
        var onLocalStorageEvent = function(e){
            if(e.key == "openpages"){
                // Listen if anybody else opening the same page!
                localStorage.page_available = Date.now();
            }
            if(e.key == "page_available"){
                alert("One more page already open");
            }
        };
        window.addEventListener('storage', onLocalStorageEvent, false);
</script>

This is quite simple. sometimes you need to identify the string position to replace it with another string.

Example 2

The strpos itself it returns the position value, with that we can identify the string exist and position of the string starts.

<?php 
 $first = " This is first string to find the first word and replace the first with second";
 echo strpos($first, 'first') ;
?>

That’s it. You can try this is small function to do it with existing php itself.

commenter

About Varadharaj V

The founder of Kvcodes, Varadharaj V is an ERP Analyst and a Web developer specializing in WordPress(WP), WP Theme development, WP Plugin development, Frontaccounting(FA), Sales, Purchases, Inventory, Ledgers, Payroll & HRM, CRM, FA Core Customization, PHP and Data Analyst. Database Management Advance Level

Comment Below

Your email address will not be published. Required fields are marked *

*

Current ye@r *

Menu

Sidebar