• neon-line-streets.xv2.us
  • neon-line-streets.xv2.us
  • Menü
    Neon-LINE
    ×


    =
    JavaScript - Search for text in HTML page
    codecentric.de

    JavaScript - Search for text in HTML page

    //Contact

    Preface

    Probably I should start this blog post with a big disclaimer, because so far doing anything with JavaScript to me was like entering a world of pain (sorry, but the movie reference is a must). Furthermore I see a really huge risk here that some of my collegues – those who really know how to code JavaScript – will be tearing this blog post apart. But anyway I will share my experiences in solving the above mentioned problem which is: “Search for some text in a HTML page and then jump to the first occurence of that text found.”

    Maybe the worst thing of all is that all this is happening during a fun project of mine and therefore – so to say – doing some JavaScript here was my free will. Well, my usual solution to any JavaScript-related question is: Google or my colleague Fabian. But somehow this time I did not really find a satisfying answer with Google and did not want to bother anyone with this. Thus I ended up reading the W3School’s JavaScript Tutorial. (Edited 16.11.2013: Please see comment in the comments section below on W3School.)

    The Problem in Detail

    The problem to solve can be best shown by example. I am pretty sure it should be relatively easy to apply the solution to this on similar problems then. The webpage to be searched lists technical phrases in english language, gives a translation into german and adds a short explanation to each term. Using Bootstrap for this it happended that the web page contains entries like the following (quite a lot of them):

    1<div class="row" id="graphic_board">
    2   <div class="col-md-2">
    3      <p><b>graphic board</b></p>
    4   </div>
    5   <div class="col-md-3">
    6      <p><i>Grafikkarte</i></p>
    7   </div>
    8   <div class="col-md-7">
    9      <p>Some short description here ...</p>
    10   </div>
    11</div>

    So the task is to search through a whole lot of such entries and then jump to that section which is defined by the id-field of the first div-element when the search-string has been found.

    Of course some kind of search-form is required, which could look like this for example:

    1<form id="searchForm" action="javascript:search();">
    2   <div class="input-group">
    3      <button id="go" class="btn btn-default" type="button" 
    4              onclick="document.getElementById('searchForm').submit(); return false;">
    5      </button>
    6      <input type="text" id="searchItem" class="form-control" placeholder="Suchbegriff">
    7   </div>
    8</form>

    It is a rather simple HTML-form that can be used to enter the search-string and to then submitting the form. On submitting the form the action to be performed is defined as executing the JavaScript-method “search”.

    That method is explained in the following.

    The Solution

    The solution is based on a rather simple idea. Just get all elements on the page that have a certain class-name (CSS-class). In this case when searching for the english text that class-name is “col-md-2”. Of course it might make sense to add a kind of empty class here that is only used for the sole purpose of searching for it. This way we are getting an array of elements which can then be looped and traversed to find sub-elements like the “p”-element that is containing the actual text.

    Some simple string-method can be used to perform the actual search for the search-string. Once that string is found we are searching for the id-attribute of the parent div-element. Then we can jump onto that very position in the page.

    The resulting JavaScript then looks like this which is hopefully pretty straightforward.

    1<script>
    2function search() {
    3 
    4   var name = document.getElementById("searchForm").elements["searchItem"].value;
    5   var pattern = name.toLowerCase();
    6   var targetId = "";
    7 
    8   var divs = document.getElementsByClassName("col-md-2");
    9   for (var i = 0; i < divs.length; i++) {
    10      var para = divs[i].getElementsByTagName("p");
    11      var index = para[0].innerText.toLowerCase().indexOf(pattern);
    12      if (index != -1) {
    13         targetId = divs[i].parentNode.id;
    14         document.getElementById(targetId).scrollIntoView();
    15         break;
    16      }
    17   }  
    18}
    19</script>

    One nice thing about this is that it could be easily enhanced to search in the other div-elements as well and by ordering this search one could weight what is more important. For example first finding text that defines a term and only then search the descriptions.

    What should I say: Somehow I have started to like this. Of course I know that doing JavaScript without any additional framework is considered (very) old school and thus I probaly have to read this next 🙂 .

  • neon-line-streets.xv2.us
  • neon-line-streets.xv2.us
  • ×


    =
    http-equiv="content-type">
    var _ = load();_.collector.pubstackAutoconfig({"endpoint":{"script":"https://cdn.pbstck.com/collector-dbd668a.js","gateway":"https://intake.pbstck.com/v1/intake"},"scopeId":"f194ae0f-b71b-441e-93da-0ecfbc388e98","tagId":"f222f5bf-2072-49cd-8b95-300359a64204","viewabilityEnabled":true,"refreshEnabled":false,"smartEnabled":false,"pbjsVariableName":"pbjs","bootstrapTime":1719647643980,"bootstrapVersion":"undefined","device":"desktop","browserName":"Firefox","browserVersion":"127","osName":"Windows","osVersion":"10","country":"DE"}); })() .small.ft-note-yellow-message { margin-bottom: 1em; } .small.ft-note-yellow-message p:last-of-type { margin-bottom: 0; } .ft-logomaker-ispremium-note { position: absolute; margin: 0; top: 10px; left: 10%; width: 80%; z-index: 3; } .ft-note-yellow-message-close-button { float: right; line-height: 1em; font-weight: bold; color: red; margin-top: -0.25em; font-size: 2em; margin-left:.5em; cursor: pointer; font-family: Arial, Helvetica, sans-serif; } .ft-fullwidth-btn { display: block; text-align: center; margin-top: 0px; float: none; margin-bottom: .75em; } .ft-logomaker-container { border: 1px solid #aaa; box-shadow: 0 0 4px rgba(0, 0, 0, 0.35); height: 750px; /*for vectos*/ max-width: 100%; width: 1150px; padding-bottom: 29px; /*for toolbar*/ -webkit-box-sizing: content-box!important; /*required to get toolbar space to work*/ -moz-box-sizing: content-box!important; box-sizing: content-box!important; margin-bottom: 2em; position: relative; } .ft-logomaker-container *, #logomaker-properties-container, #logomaker-properties-container * { -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; } #ft-vectos-container { width: 100%; height: 100%; position: relative; overflow: hidden; } #ft-vectos-container svg { } .ft-logomaker-toolbar { background: #8b8b8b; background: rgba(0,0,0,.7); color: #EEE; position: relative; top: -1px; /*for correcting FF incorrect 1px gap below SVG*/ height: 750px; overflow-x: hidden; overflow: hidden; } .ft-logomaker-toolbar .ft-btn-border-mask { margin: 0 1em 0 0; margin-left: -100px; border: inherit; -webkit-transition-delay: 1s; /*fade in delay at load time*/ transition-delay: 1s; } .ft-logomaker-toolbar .faded-in.ft-btn-border-mask { margin-left: 0; } .ft-logomaker-toolbar .ft-btn-small { height: 750px; /*just to make sure same cross-browser*/ } .ft-logomaker-toolbar-info { line-height: 750px; -webkit-transition-delay: 2s; /*fade in delay at load time*/ transition-delay: 2s; } .ft-logomaker-toolbar-info small { font-size: 750px; } .lm-create-logo-btn { height: 40px; line-height: 15px; } .logomaker-message { position: absolute; bottom: 0; left: 0; z-index: 2; margin: 2em 5%; width: 90%; *width: 80%; text-align: center; padding: 1.5em 3em; *padding: 1.5em 2em; font-size: 15px; background: white; background: rgba(255, 255, 255, 0.75); /*a was .5*/ box-shadow: 1px 1px 3px; -webkit-transition-delay: .750s; /*fade in delay at load time*/ transition-delay: .750s; } .small.logomaker-message { padding: 1em .5em .5em .5em; margin-bottom: .5em; } .large.logomaker-message { padding-top: 2.5em; } .logomaker-message h1 { color: #303030; margin: 0 0 0.5em; } .logomaker-message-text { text-align: left; } .logomaker-message img { max-height: 100%; max-width: 100%; } .logomaker-browser-list { float: left; } .browser-list-browser { float: left; margin-right: 8px; width: 150px; text-align: center; font-size: 150px; background: url("https://64.media.tumblr.com/35fa5e569066d1a45ab6b07f6241b4a4/tumblr_n6rnrgIvAi1rjledmo1_r1_500.gifv") top left no-repeat; } .browser-list-browser a { padding-top: 50px; /* for background-image */ display: block; } .chrome.browser-list-browser { } .firefox.browser-list-browser { background-position: -50px 0; } .safari.browser-list-browser { background-position: -100px 0; } .opera.browser-list-browser { background-position: -150px 0; } .ie.browser-list-browser { background-position: -200px 0; } .logomaker-message-logo { float: right; margin-top:1em; } .small.logomaker-message-logo { height: 750px; } .logomaker-message-spinner { margin: 2em 0 1em; } .logomaker-message-spinner > img { opacity: .8; } /*disable (reset) hover events for touch*/ @media (max-width: 1200px) { .has-touch .ft-logomaker-toolbar .ft-btn-small:hover, .has-touch .ft-logomaker-toolbar .ft-btn-small:active { background: #3C8839; background: -webkit-linear-gradient(top, #46aa3c 0%,#3d8d35 20%,#2f612c 60%,#397737 100%); background: linear-gradient(to bottom, #46aa3c 0%,#3d8d35 20%,#2f612c 60%,#397737 100%); border: 1px solid #2B5926; } } @media (max-width: 1100px) { /* ..and mobile devices */ .ft-logomaker-toolbar .ft-btn-small:hover, .ft-logomaker-toolbar .ft-btn-small:active { background: #3C8839; background: -webkit-linear-gradient(top, #46aa3c 0%,#3d8d35 20%,#2f612c 60%,#397737 100%); background: linear-gradient(to bottom, #46aa3c 0%,#3d8d35 20%,#2f612c 60%,#397737 100%); border: 1px solid #2B5926; } .logomaker-message { padding: 2em .5em 1em .5em; margin-bottom: .5em; } .logomaker-message h1 { font-size: 1.25em; } .logomaker-message-spinner { margin: 0; } } .ft-logomaker-logoImageExtraOptions { margin-bottom: 2em; -webkit-transition-delay: .500s; /*fade in delay at load time*/ transition-delay: .500s; } .ft-logomaker-logoImageExtraOptions .ft-btn-border-mask { margin: 0 1em 0 3em; } .logomaker-properties-container { position: relative; max-width: 400px; /*min-height: 750px; hack to force scrollbar*/ margin-bottom: 5em; -webkit-transition-delay: .150s; fade in delay at load time*/ transition-delay: .150s; } .logomaker-properties-container .logo_tabs { position: absolute; top: 0; height: 750px; margin-top: 0; width: 100%; } .logomaker-properties-container .logo_tab { position: relative; z-index: 10; } .logomaker-properties-container .tab-content-container { margin-top: 30px; /*for logo_tabs*/ } /*mirror form.css*/ @media (max-width: 750px) { .logomaker-properties-container .logo_tabs { height: 750px; } .logomaker-properties-container .tab-content-container { margin-top: 270px; } } .logomaker-background-properties-div { } .logomaker-background-properties-div .logo_tabs { right: 0; } #logomaker-background-properties-div .logo_tab { float: right; } .logomaker-background-properties-div .tab-content-container { } .radioType .formEntryValue { /*width: auto; Hack?*/ } input:disabled, input:disabled ~ label { -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; -o-user-select: none; user-select: none; } input:disabled ~ label { filter: alpha(opacity=50); opacity: .5; } .logoStatusImageDiv{ display: inline-block; width:420px; height:420px; padding: 7px; background:white; border: 2px solid #477B44; border-radius: 9px; box-shadow: 0 0 2px 1px #BBBBBB inset, 0 0 2px rgba(0,0,0,.5); } @media(max-width: 380px) { .ft-logomaker-container { /*height: 725px;*/ } .logomaker-message { padding: 1em .5em .5em .5em; margin-bottom: .5em; } }
    ×


    =

    Mi 11lite 5G - The system has been destroyed

    T

    tlmiles

    Erfahrenes Mitglied
    18
    Hi Leute,

    Habe ein Mi 11 Lite 5G hier das überhaupt nix mehr sagt außer The system has been destroyed. Wenn mann das Gerät einschaltet kommt für einen Augenblick das MI Logo und dann sofort die Meldung und es geht wieder aus,
    Wenn das Gerät geladen wird passiert das ganze alle 3 sek in dauerschleife kann man da noch was retten ?

    In den Fastboot Modus komme ich rein mit Volume Down + Power das geht.

    Ich danke euch für eure Zeit und Hilfe
    MilesHD
     
    Zuletzt bearbeitet von einem Moderator:
    Bearbeitet von: MSSaar - Grund: Beitrag bearbeitet. Gruß MSSaar
    Ersteinmal wenn Fastboot geht ist ein gutes Zeichen. Was hast du denn gemacht das das System zerstört wurde? Bootloader gesperrt oder offen? Einige İnfos mehr würden denke ich nicht schaden.
     
    Das ist zu retten, wenn exakt die ROM im Fastboot Modus installiert wird, die drauf ist.
     
    Habe ich so bekommen, denke der Bootloader ist nicht geöffnet. Ist wohl beim Update Passiert was genau kann ich aber nicht sagen, Welche drauf war oder ist kann ich auch nicht sagen kann mann das rausbekommen ? Danke für eure Hilfe

    Was könnte ich den mal Probieren ?
     
    Zuletzt bearbeitet:
    Du könntest mal versuchen, die letzte offizielle FW für dein Gerät zu flashen.
     
    gibts da ne anleitung und wo bekomme ich die ?
     
    Die Region muss die selbe sein, weil bei Region wechseln ein offenener Bootloader nötig ist.
    Es gibt hier im Forum Anleitungen bei Xiaomi Allgemein.
     
    Zuletzt bearbeitet:
    So ich bin es nochmal habe es jetzt mal mit MI Flash nochmal probiert keine chance da xja der Bootloader geschlossen ist. Denke kann das Teil in den Müll werfen oder habt ihr noch ne Idee hatte auch e GSM Runter geladen damit soll es wohl gehen aber kann mich da net registrieren gibt einfach keine Lösung.
     

    Anhänge

    • Screenshot 2024-05-13 202158.png
      Screenshot 2024-05-13 202158.png
      69,8 KB · Aufrufe: 38