SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Addict Garrett's Avatar
    Join Date
    Feb 2001
    Location
    England
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question prompts and souce viewing

    hello

    have two questions here...

    first one is to do with alerts or prompts, not sure which, is'nt there a way of displaying lots of text in an alert dialog? ie instead of just having the single line like in prompt there is a scrollable multiline???

    and second question, is there a way for javascript to ether A pop open the source window of the page (ie ctrl c / apple c) or B to display the pages source within a textarea or something??

    thanks in advance
    gar

  2. #2
    SitePoint Addict
    Join Date
    Aug 2001
    Location
    Los Angeles, CA
    Posts
    346
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The newline character (\n) creates a line break in alerts/prompts...sort of like the <BR> tag for JavaScript.

    You can provide a link to view the source code for the page, but I'm not sure about displaying the source code dynamically in a textarea box...

    http://www.web-source.net/javascript_view_source2.htm

  3. #3
    SitePoint Addict Garrett's Avatar
    Join Date
    Feb 2001
    Location
    England
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by gregc
    The newline character (\n) creates a line break in alerts/prompts...sort of like the <BR> tag for JavaScript.
    it does but thats not quite what i'm searching for, i think this is more to do with the prompt() the field should be scrollable, sort of like a <textarea> input??? any ideas??


    Quote Originally Posted by gregc
    You can provide a link to view the source code for the page, but I'm not sure about displaying the source code dynamically in a textarea box...

    http://www.web-source.net/javascript_view_source2.htm
    this was what i had come accross, however it must be some sort a hack because it only works on ns 4.5 on macintosh, does'nt work with ether ns 6 or ie 5. not worried too much about displaying the code in a textarea, i can do this with php, was wondering whether that source popup was valid or not?

    a+
    gar

  4. #4
    SitePoint Addict
    Join Date
    Aug 2001
    Location
    Los Angeles, CA
    Posts
    346
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No, I don't think you can make a prompt or alert scrollable...those newlines are definitely useful for neatening out large amounts of text though.

    Yes, the view source scripts you see on the web are most likely legit, especially the one I provided the link for...I've seen these work on my computer all the time, granted they may not work on every computer, but they do work on the more recent browsers.

  5. #5
    SitePoint Addict Garrett's Avatar
    Join Date
    Feb 2001
    Location
    England
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by gregc
    Yes, the view source scripts you see on the web are most likely legit, especially the one I provided the link for...I've seen these work on my computer all the time, granted they may not work on every computer, but they do work on the more recent browsers.
    well as i a said does'nt work on ie5 or ns6 on Macintosh so you don't get much more recent than that!!

    a+
    gar

  6. #6
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, the view-source:// protocol is one of IE's predefined protocols. Since it relies on launching Windows Notepad, I surmise that it only works on Windows-based PCs.

    You can get the entire HTML of the page as a string (excluding the doctype) with document.documentElement.outerHTML

    I don't know about other browsers for sure, but recent Gecko browsers and IE5+ support it.
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  7. #7
    SitePoint Addict Garrett's Avatar
    Join Date
    Feb 2001
    Location
    England
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by beetle
    I don't know about other browsers for sure, but recent Gecko browsers and IE5+ support it.
    yep and it seems to work on mac no problem, give me a hand here, it works but does some odd things like capitalises some of the code and puts the javascript into the body, copy and paste the code below and you'll see what i mean!

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en">
    
    <head>
    <title>title</title>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
    <meta name="description" content="description" />
    <meta name="author" content="author" />
    <meta name="keywords" content="keywords" />
    <link rel="stylesheet" href="resources/styles.css" type="text/css">
    
    </head>
    
    <body>
    
    <form name="pagesource">
    <textarea name="thecode" rows="20" cols="100"></textarea>
    </form>
    
    </body>
    </html>
    
    
    <SCRIPT Language="JavaScript1.3">
    <!-- Begin
    
    var thesource = document.documentElement.outerHTML;
    window.document.pagesource.thecode.value = thesource;
    
    // End -->
    </script>
    a+
    gar

  8. #8
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, you see the HTML as the browser sees it, and not as it was originally written. That's the reason for the tag upper-casing and other oddities.

    The reason your scripting ends up inside the body is because that's where it belongs, and the browser puts it there. Why an earth would you try to put HTML outside of <html>? HTML markup can't exist outside of the <html> element. The reason should be self-evident.
    Last edited by beetle; Mar 27, 2003 at 11:53.
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  9. #9
    SitePoint Addict Garrett's Avatar
    Join Date
    Feb 2001
    Location
    England
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by beetle
    Well, you see the HTML as the browser sees it, and not as it was originally written. That's the reason for the tag upper-casing and other oddities.

    The reason your scripting ends up inside the body is because that's where it belongs, and the browser puts it there. Why an earth would you try to put HTML outside of <html>? HTML markup can't exist outside of the <html> element. The reason should be self-evident.
    well the answer to your question is in the first part of what you said, normally i would'nt put the javascript outside the <html> but if you don't here it can't read to the end of the file! so for example if you put the javascript into the head it will only read the source as far as the head.

    is'nt the source in the browser how the browser sees the html or is that just a representation for the user as well?

    a+
    gar

  10. #10
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, first about the source thing, a little clarification.

    Normally when you use View >> Source or whatever, you see the downloaded HTML, so it appears there just as it does in your editor. If you use scripting to retrieve the HTML, you end up seeing it as the DOM sees it.

    Now, about the script thing. I apologize, I didn't know your JS knowlege was basic. Put this in the <head>
    Code:
    <script type="text/javascript">
    window.onload = function()
    {
    	window.document.pagesource.thecode.value = document.documentElement.outerHTML;
    }
    </script>
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  11. #11
    SitePoint Addict Garrett's Avatar
    Join Date
    Feb 2001
    Location
    England
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by beetle
    Now, about the script thing. I apologize, I didn't know your JS knowlege was basic. Put this in the <head>
    Code:
    <script type="text/javascript">
    window.onload = function()
    {
    	window.document.pagesource.thecode.value = document.documentElement.outerHTML;
    }
    </script>
    my knowledge is far from basic, i had already tried that and it does'nt work!!!

    a+
    gar

  12. #12
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's because of that antiquated commenting mechanism you're using

    <!--
    // -->

    That's designed to hide javascript from browsers that can read it but not interpret it. Those days are long gone, we're talking like version 3 browsers.

    Remove those silly comments and you should be fine

    Or, upgrade them to what you should be using for an XHTML document, especially one that is STRICT.

    <script type="text/javascript">
    // <![CDATA[
    scripting
    // ]]>
    </script>

    Note: The language attribute on SCRIPT tags in intended to do the same thing as the old HTML comments, tell the older browsers to ignore it if they don't support it. Again, those days are long gone. Especially since a langauge attribute on your SCRIPT tag will make your XHTML-Strict document invalid.
    Last edited by beetle; Mar 27, 2003 at 16:13.
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev





Bookmarks

Posting Permissions

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