/    Sign up×
Community /Pin to ProfileBookmark

Is there a name for client side web agents?

I’m having a hard time creating an html document that:

[list=1]

  • [*]

    fishes around the net for some information when I open it,

  • [*]

    creates a new version of itself in a new page,

  • [*]

    is finished when I save/overwrite it.

  • [/list]

    Ironically 1 & 2 were not that difficult. And what seemed like it should be trivial is turning out to be anything but… step 3. Everything looks right when the scripts finish, but save fails claiming it can’t be done. View source reveals nothing. innerHTML is correct, but doesn’t do me much good since I know of no way to write it to a file.

    Does anyone know of an example of such a page? Or of any way to update the source HTML (and not just the DOM) of the current page?

    The goal here is to end up with a sort of application that can program my EyeTV to capture the short films that appear on [url=http://www.tcm.com/]TCM.[/url] What would you call something like this? (besides a fools errand)

    to post a comment
    JavaScript

    13 Comments(s)

    Copy linkTweet thisAlerts:
    @phpnoviceJul 04.2006 — AJAX would be required to send the source of the HTML page back to the server. However, server-side code is required, at that point, to actually save the document on the server. In case you don't know what AJAX is, here is an introductory tutorial:

    http://jibbering.com/2002/4/httprequest.html
    Copy linkTweet thisAlerts:
    @felgallJul 04.2006 — The server side processing is also essential if you want the search to go outside of the current domain OR outside of the pages currently displayed in the browser window.
    Copy linkTweet thisAlerts:
    @ananiasauthorJul 05.2006 — Let me try again because I can tell from your responses that I have not made my problem clear. Because there is no server involved. (Whether I generate the new DOM elements via information received via xmlhttp requests or from user input is of no consequence.)

    The following small html file illustrates the problem:

    <html><head><title>Bootstrapper</title>

    <script type='text/javascript'>

    function addComment(msg) {

    var son, node, opts = "toolbar=yes,location=yes,directories=yes,status=yes," +

    "menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes";

    node = document.createElement("p");

    node.appendChild(document.createTextNode(new Date().toString() + ": " + msg));

    document.body.appendChild(node);

    node = document.documentElement.innerHTML;

    node = node.replace(/<title>([^>]+)</title>/i,"<title>Son of $1</title>");

    son = "Son of " + /<title>([^>]+)</title>/i.exec(node)[1];

    son = window.open("", son, opts);

    son.document.write(node);

    son.document.close();

    son.document.focus();

    }

    </script>

    </head>

    <body>

    <textarea id="source" onchange="addComment(this.value)" cols="70" rows="20"></textarea>

    </body>

    </html>

    This works in Mozilla, but not Safari. Can anyone figure out how to make it work correctly in Safari.

    I notice that in Camino it does something very strange... if you close the original window before you do the save, then the view source command displays the old source.
    Copy linkTweet thisAlerts:
    @phpnoviceJul 05.2006 — If there is no server involved, then you cannot use the XMLHttpRequest object.
    Copy linkTweet thisAlerts:
    @ananiasauthorJul 05.2006 — If there is no server involved, then you cannot use the XMLHttpRequest object.[/QUOTE]There is no server involved that I could have any effect on--the html page is local--just a file on my machine. The xmlhttp object is simply used to fetch information from TCM's and IMDB's web sites for incorporation into the local page. It has nothing to do with the problem I am having with Safari.
    Copy linkTweet thisAlerts:
    @phpnoviceJul 05.2006 — To my knowledge, the only way to programmatically save a local HTML document and its programmatically-generated content is to use an ActiveX control to do so. I could be wrong, but I don't think that will help with Safari.
    Copy linkTweet thisAlerts:
    @ananiasauthorJul 06.2006 — To my knowledge, the only way to programmatically save a local HTML document and its programmatically-generated content is to use an ActiveX control to do so...[/QUOTE]I do appreciate the attempts to help, but I still think you are reading too much into it. I'm not trying to invoke the save or save as command from a script. Simply creating a new page and wondering why I cannot save the new page, as a user, by invoking the menu command to do so. I am completely stumped as to what is going on with this incredibly simple script:[code=html]<html><head><title>Bootstrapper</title>
    <script type='text/javascript'>
    var saved = true;
    function addComment(msg) {
    var son, node, opts = "toolbar=yes,location=yes,directories=yes,status=yes," +
    "menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes";
    node = document.createElement("p");
    node.appendChild(document.createTextNode(new Date().toString() + ": " + msg));
    document.body.appendChild(node);
    node = document.documentElement.innerHTML;
    node = node.replace(/<title>([^>]+)</title>/i,"<title>Son of $1</title>");
    node = node.replace(/true;/i,"false;");
    son = "Son of " + /<title>([^>]+)</title>/i.exec(node)[1];
    son = window.open("", son, opts);
    son.document.write(node);
    son.document.close();
    son.focus();
    }
    function showTitle() {
    if (saved) return ;
    var t = document.documentElement.firstChild.firstChild.firstChild.nodeValue;
    var s = document.documentElement.innerHTML;
    document.getElementById("source").value = s;
    alert(document.location.href + " " + t + " is " + s.length + " bytes.");
    }
    </script>
    </head>
    <body onload="showTitle()">
    <textarea id="source" onchange="addComment(this.value)" cols="70" rows="20"></textarea>
    </body>
    </html>[/code]
    If you try it, you'll notice that the new page is generated correctly but the title and location are not displayed in the frame. The DOM appears intact. But try to save the page and it fails. Try to refresh it and it disappears. The innerHTML for the entire page is copied into the text field to make it easy to check and it is correct as well. The page works too (spawing yet another page that appears intact but really isn't either if you add text) Camino and Mozilla do not have this problem. I'm looking for some way to generate that new page in Safari that [i]allows[/i] it to be save by the user (if they so choose of course.)
    Copy linkTweet thisAlerts:
    @phpnoviceJul 06.2006 — There is an error in your code. In what browser are you testing?
    Copy linkTweet thisAlerts:
    @ananiasauthorJul 06.2006 — There is an error in your code. In what browser are you testing?[/QUOTE]Safari, Mozilla, and Camino. Can you tell me more about the error?
    Copy linkTweet thisAlerts:
    @phpnoviceJul 06.2006 — In Mozilla, open the JavaScript Console from the Tools menu. Then try out your page.

    ...and, by the way, IE gives a different erorr message than Firefox does.
    Copy linkTweet thisAlerts:
    @ananiasauthorJul 06.2006 — In Mozilla, open the JavaScript Console from the Tools menu. Then try out your page.

    ...and, by the way, IE gives a different erorr message than Firefox does.[/QUOTE]
    Whoops... windows focus, not documents. Just delete the .document part of son.document.focus(); I have IE but don't bother with it since it is so old, no longer maintained, and supports a different DOM.

    In any event, the error is inconsequential having no effect on whether the newly generated page can be saved or not from Mozilla or Safari. Mozilla allows it, Safari doesn't without saying why even. Can you think of something I could do to the script to make it work in Safari?

    Do you think it would make a difference if I created the newly generated page some other way (without using window.open?) I vaguely recall that there is some other way to do it but can't remember what it is. Do you know of any?
    Copy linkTweet thisAlerts:
    @phpnoviceJul 06.2006 — In any event, the error is inconsequential ...[/QUOTE]
    Perhaps you don't actually mean to be so dismissive of errors. Any error prevents your script from running as intended. Therefore, unintended results cannot be relied upon as indicitive of other problems. Errors must all be dealt with first -- before the final results can be correctly evaluated.
    Copy linkTweet thisAlerts:
    @phpnoviceJul 06.2006 — At any rate... I don't have Safari and will probably never bother with any other browser than the three I test with -- IE6, NS7+, and Firefox. After correcting the errors mentioned, the generated page appears to be saved fine. Sorry, but I don't know what errors Safari may have with it.
    ×

    Success!

    Help @ananias spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.30,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...