Header Ads

Header ADS

Mouse and keyboard Prevent Disable Ctrl+U Ctrl+Shift+I left-click, and right-click using JavaScript

 //Laravel Blade code in a specific page

<div class="w-100 px-md-4">

    <div class="card-container dahbooks">

        @if ($books)

            @foreach ($books as $book )

            <div class="card">

               @if (\App\Models\BookAccess::where('book_id', $book->id)->where('user_id', Auth::id())->exists())

                    <!-- If payment_id exists, show this link -->

                    <a href="{{ route('user.pdfview', ['id' => $book->id]) }}">

                        <img src="{{ asset($book->image) }}" alt="">

                        <div class="card-content">

                            <h5>{{ $book->title }}</h5>

                            <p>Author: {{ $book->author_name }}</p>

                            <p>Price: {{ $book->price }}$</p>

                        </div>

                    </a>

                @else

                    <!-- If payment_id is NULL, show this link -->

                    <a href="" data-bs-toggle="modal" data-bs-target="#exampleModal{{ $book->id }}">

                        <img src="{{ asset($book->image) }}" alt="">

                        <div class="card-content">

                            <h5>{{ $book->title }}</h5>

                            <p>Author: {{ $book->author_name }}</p>

                            <p>Price: {{ $book->price }}$</p>

                        </div>

                    </a>

                @endif

               

               

            </div>

            @endforeach

        @endif

    </div>

</div>


@if ($books)

@foreach ($books as $book )

<div class="modal fade dashbookdetails" id="exampleModal{{ $book->id }}" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">

    <div class="modal-dialog modal-dialog-centered">

      <div class="modal-content">

        <div class="modal-body">

            <button type="button" class="closebtn" data-bs-dismiss="modal" aria-label="Close"><i class="fa-solid fa-rectangle-xmark"></i></button>

            <div class="d-flex column-gap-3">

                <img src="{{ asset($book->image) }}" width="40%" alt="">

                <div class="card-content">

                    <h5>{{ $book->title }}</h3>

                        <p>Author: {{ $book->author_name }} </p>

                    <p>Price: {{ $book->price }}$ </p>

                </div>

            </div>

            <p> Description: </p>

            

            <p id="textContent" class="d-inline">

                {{ $book->description }}

              </p>

              <span id="toggleBtn" class="text-submit" style="cursor: pointer;">... See More</span>

            <div class="modal-footer justify-content-start px-0 mt-3">

                <p> <strong>You have to Purchase or request hard copy to read our books !</strong>  </p>

                @if ($access->where('book_id', $book->id)->where('user_id', Auth::user()->id)->isNotEmpty())


                <a href="{{ route('user.pdfview' , $book->id ) }}" type="button" class="btn btn-submit">Read Now !</a>

                    @else

                    <a href="{{ route('user.checkout' , $book->id ) }}" type="button" class="btn btn-submit">Buy Now !</a>

                @endif

                

              </div>

        </div>

        

      </div>

    </div>

  </div>

  @endforeach

  @endif


//Js code

<script>

    document.addEventListener("contextmenu", function (e) {

        e.preventDefault(); // Disable right-click

    });


    document.addEventListener("keydown", function (e) {

        if (

            (e.ctrlKey && e.key === "u") ||  // Disable Ctrl+U (View Source)

            (e.ctrlKey && e.shiftKey && e.key === "I") || // Disable Ctrl+Shift+I (DevTools)

            (e.ctrlKey && e.shiftKey && e.key === "J") || // Disable Ctrl+Shift+J (Console)

            (e.ctrlKey && e.key === "s") || // Disable Ctrl+S (Save Page)

            (e.ctrlKey && e.key === "p") || // Disable Ctrl+P (Print)

            (e.ctrlKey && e.key === "c") || // Disable Ctrl+C (Copy)

            (e.metaKey && e.key === "u") || // Disable Command+U for Mac users

            (e.metaKey && e.shiftKey && e.key === "I") // Disable Command+Shift+I for Mac users

        ) {

            e.preventDefault();

        }

    });


    document.addEventListener("mousedown", function (e) {

        if (e.button === 0 || e.button === 2) { // Disable left-click & right-click

            e.preventDefault();

        }

    });

</script>


No comments

Theme images by fpm. Powered by Blogger.