Web Analytics Made Easy -
StatCounter Javascript for if Else HTML - CodingForum

Announcement

Collapse
No announcement yet.

Javascript for if Else HTML

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Javascript for if Else HTML

    I’m trying to use javascript to display html conditinally.
    If condition a is met I want to display an iframe section. If the condition is not met I want to display the page I was going to show in an iframe as the whole page. Is there a way to use javascript to show conditional html?

  • #2
    <!DOCTYPE html>
    <html>
    <body>

    <script>
    if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)){
    document.write("Not Mobile");
    }
    else{
    document.write("Hello, world!");
    }
    </script>
    </body>
    </html>

    Comment


    • #3
      Originally posted by Davidlphillips View Post
      <!DOCTYPE html>
      <html>
      <body>

      <script>
      if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)){
      document.write("Not Mobile");
      }
      else{
      document.write("Hello, world!");
      }
      </script>
      </body>
      </html>
      Not sure how to mark this as solution.

      Comment


      • #4
        The code is following to display Html dynamically :

        HTML Code:
        <!DOCTYPE html>
        <html lang="en">
        
        <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Document</title>
        <script>
        
        function myFunction(x) {
        var str = document.getElementById('txtInput').value;
        if (str == "a") {
        document.getElementById("iframeSection").style.visibility = "visible";
        document.getElementById("iframeSection").style.border = "solid black";
        }
        else {
        document.getElementById("iframeSection").style.visibility = "hidden";
        }
        }
        
        </script>
        
        </head>
        
        <body>
        <input type="text" id="txtInput" onkeyup="myFunction(this)" value="" name="txtInput" placeholder="Enter ">
        <section id="iframeSection" style="visibility: hidden;">
        <p>I am I frame Section</p>
        <iframe id="my Frame" width="100%" height="100%" src="C:\Users\LENOVO\Desktop\jsdemo.html"
        style="border:solid black;visibility: visible;" />
        </section>
        
        </body>
        
        </html>
        ASP.Net Software Development

        Comment

        Working...
        X