Note that there are some explanatory texts on larger screens.

plurals
  1. POBookmarklet to submit page source to form
    primarykey
    data
    text
    <p>I'm using a bookmarklet to send the current page source to a server function which then processes it (stores it, no information needs to be returned to the user). </p> <p>Warning: ugly Javascript ahead, it's not a language I normally need to use.</p> <p>Here's the bookmarklet, pretty-printed for ease of reading:</p> <pre><code>javascript: (function () { var h = document.documentElement.innerHTML; function c(a, b) { var c = document.createElement("textarea"); c.name = a; c.value = b; d.appendChild(c) }(document), d = document.createElement("form"); d.method = "POST"; d.action = "http://example.com/do.php"; d.enctype = "multipart/form-data"; d.target = "_blank"; c("h", h); c("u", "1234"); document.body.appendChild(d); d.submit(); })(); </code></pre> <p>This basically works, "do.php" receives the head and body sections in form variable h.</p> <p>However, it only seems to work once for each page. If the bookmarklet is pressed twice for the same page, nothing happens. When the page is reloaded, it works again. Is there something I should be resetting? (running once is enough of course, but it would be nice to give some feedback to the user the second time it is pressed).</p> <p>Secondly, this pops up a new tab/window. I can work around this by having do.php return some javascript to close the window (note: this is just for testing purposes, not real code):</p> <pre><code>&lt;?php $page = $_REQUEST['h']; file_put_contents('/tmp/work.txt', $page); echo '&lt;script type="text/javascript"&gt;window.close();&lt;/script&gt;"'; ?&gt; </code></pre> <p>Ugly. Quick flash of the new tab, then it's gone. Is there a better approach? A "success" message would be nice, but I can't see how to incorporate that.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload