Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Apr 2006
    Posts
    231
    Thanks
    9
    Thanked 1 Time in 1 Post

    Screen Size and output

    I have madea website, which is pretty unfortunate. I was originally messing around for about 2 days, and came up with a great layout. The bad side is that the background is 1030px. If screen width is greater than 1030 (1024) then it shows up as blank space. I came up with some javascript code based on the trusty google.com. I want:

    If screen width is less than 1024, print <a href="JSmedia.php">Continue</a>
    Else <a href="javascriptopUp('JSmedia.php')">Continue</a>

    Code:
    <script language='Javascript'>
    <!--
    windowheight=screen.height;
    function popUp(URL) {
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=1,scrollbars=1,location=1,statusbar=0,menubar=0,resizable=0,width=1032,height="+ windowheight +",left = 125,top = 0,title=js');");
    }
    if (screen.width <=1024){
    --------------------------- 
    }
    else{
    ---------------------------
    }
    //-->
    </script>
    I don't know how to print/echo a link in javascript. the dashes represent the displayed links. That's where I am stuck.

  • #2
    Senior Coder Arbitrator's Avatar
    Join Date
    Mar 2006
    Location
    Splendora, Texas, United States of America
    Posts
    3,300
    Thanks
    28
    Thanked 275 Times in 269 Posts
    Are you asking how you would dynamically create an element?

    Code:
    function createAnchor() {
      var anchor = document.createElement("a");
      anchor.setAttribute("href", "JSmedia.php");
      var text = document.createTextNode("Continue");
      anchor.appendChild(text);
      document.getElementsByTagName("body")[0].appendChild(anchor);
      }
    The above code is what would go in the if statement. The getElementsByTagName("body")[0] line would change depending on where you want the anchor element to be inserted. In this case, it’s inserted as the last child of the document’s first body element.

    Oh yeah, as a side note, you should also use type="text/javascript" instead of the deprecated language="JavaScript".
    Last edited by Arbitrator; 10-24-2006 at 12:33 PM.
    For every complex problem, there is an answer that is clear, simple, and wrong.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •