Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's wrong with my browser JavaScript engine on jsbin.com? [closed]

I am new to JavaScript. I am trying to add text into a p tag and targeting it using the ID. Now, using the document.getElementById('text').innerHTML, when I set the text that contains the do word, it returns the original text in the p tag.

document.getElementById('text').innerHTML='as I add??? do';
<p id="text" class="abc">Hello</p>

It is happening only with the do word in between. Here's a GIF explaining the issue:

enter image description here

I hope I am doing this right. But, there might be some quirk that is messing with me.

like image 970
suprxd Avatar asked Jul 13 '26 13:07

suprxd


2 Answers

As commented by Juhana and jsbin member on github, it's a false positive, this can be achieved by adding // noprotect in the code.

e.g.

console.clear(); 
document.getElementById('abc').innerHTML = 'this is abc do '; 

// noprotect

p.s. As of now it's to work around to loop protection, until it's get fixed.

like image 150
shyammakwana.me Avatar answered Jul 16 '26 04:07

shyammakwana.me


When you use

document.getElementById("text").innerHTML = "abc a d";

They load this document (pretty formatted by me):

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <title>JS Bin</title>
    <style id="jsbin-css"></style>
  </head>
  <body>
    <p id="text">Hello</p>
    <script>
    try {
      document.getElementById("text").innerHTML = "abc a d";
    } catch (error) {
      throw error;
    }
    //# sourceURL=wecinoqeje.js
    </script>
  </body>
</html>

But when you use do, they completely screw up your code.

document.getElementById("text").innerHTML = "abc a do";

They probably think it's a do-while, because they have something called "loop protection". The loaded document is

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <title>JS Bin</title>
    <style id="jsbin-css"></style>
  </head>
  <body>
    <p id="text">Hello</p>
    <script>
    try {
      {
        ;
        window.runnerWindow.protect.protect({
          line: 1,
          reset: true
        });
        document.getElementById("text")
        {
          if (window.runnerWindow.protect.protect({ line: 1 }))
            break;
          .innerHTML = "abc a do";
        }
      }
    } catch (error) {
      throw error;
    }
    //# sourceURL=wecinoqeje.js
    </script>
  </body>
</html>

That's a syntax error. So your code does not run.

like image 20
Oriol Avatar answered Jul 16 '26 02:07

Oriol



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!