0

I have a bookmarklet that sets up a query string for our in-house bug-tracking system. It looks for any text that is selected, if so it sanitizes it and sets it up as a query parameter. Otherwise, it simply navigates to the top-level domain of the intranet site.

javascript:
q = document.getSelection();
u = 'http://my.top.level.domain';
if ( q == '' )
{
    q = prompt('Some profoundly insightful text','');
}
if ( q != '' )
{
    t = q.toString().replace(/wicked search text/,'sanitized replacement');
    q = u + '/results.asp?QueryParam1=qp1&QueryParam2=qp2&QueryParam3=' + escape(t);
}
else
{
    q = u;
}
window.location = q;

/* WHAT DO I PUT IN HERE? */;

undefined

What I am trying to do now, is to set the page title to the "sanitized" text. For this, I have tried various permutations of the following:

window.document.title=t;
document.onload=function()
{
    document.title=t;
};

I have swapped the order, put one before/after the other and so on. At times, I see the title briefly set to the sanitized replacement text, soon to be replaced by whatever is fetched from our intranet site. At other times, it has no effect whatsoever.

Would appreciate if anyone could help with "WHAT DO I PUT IN HERE?" portion of the bookmarklet so that the title of the 'query result' page would be set based on the 'sanitized replacement text'.

Thank you.

Happy Green Kid Naps
  • 1,611
  • 11
  • 18
  • A bookmarklet can not navigate to a new page and alter that new page. – epascarello Mar 22 '21 at 17:22
  • 1
    You are setting `document.title` of the "source" page while user is navigation away from there. You'll have to make other bookmarklet (or maybe better userscript) for the "target" page (`my.top.level.domain`) that will do something like `document.title = decodeURIComponent((new URLSearchParams(document.location.search)).get('QueryParam3'))` – myf Mar 22 '21 at 17:33
  • @epascarello -- Thank you for your comment confirming that what I seek to do is impossible via a bookmarklet. – Happy Green Kid Naps Mar 22 '21 at 18:26
  • @myf - Thank you for your explanation as to why my attempts did not work as well as a solution for how I could setup another bookmarklet for what I am after. Much appreciated. – Happy Green Kid Naps Mar 22 '21 at 18:27
  • You might be better off doing something with TamperMonkey if you can install plugins. – epascarello Mar 22 '21 at 19:44

0 Answers0