Forum Documentation Showcase Pricing Learn more

Javascript/toolbox Help

Hello Again,

I am trying to use Javascript to copy text from the plugin ‘document viewer’ from zeroqode to the clipboard. Below I have tried the 2 snippets of code separately. Both of these are in the script metatags in headers. My question is in the work flow I have ‘run javascript’ but what do I need to type in the box to get this code to actually run. Below are some screenshots of what code I am using and the box in the workflow. Thank you for your time in advance.

Very Respectfully,

Josh

You don’t need any of the scripts in your page headers. (Also, those will never work. Delete them now.)

Just drop the following into your Run JavaScript on your icon:

bubble_fn_select(window.getSelection().toString())

:point_up: What this does is calls a function bubble_fn_select (which we will create in the next step) with an argument that returns the currently selected text (window.getSelection().toString()). If no text is selected, this will return a null string.

And now you need a JavaScript to Bubble element on your page. Set it up like this:

:point_up: This creates the function bubble_fn_selectand sets it up to accept a text value (just like we are going to send it when the icon is clicked).

The selected text will be available to you as that JavascripttoBubble's value. Additionally it will trigger an event, if you want.

3 Likes

Keith,

Thank you Keith! I will try this out and let you know if I have any issues.

Very Respectfully,

Josh

Keith,

This works great for input fields but I cant get it to work with documents i upload from the document viewer. Is it possible to get a selection from the document viewer? Thank you.

Josh

Well, the above is a generic solution for returning the current selection in the browser window as a string.

However, looks like Document Viewer (looking at their demo page) winds up with the document in an iframe. So you need to do .getSelection() on contents of the iframe.

(BUT you can only do this if the origin of the iframe is same-domain. I’m pretty sure this iframe hosts from Gdrive, right?)

You’d need to expose HTML ID attributes if you haven’t already done so:

Then give your document viewer element an ID (like “keith”). Now you’ll be able to find the iframe like this (if you look at the elements in the console, you’ll see that the iframe is the first child of the bubble element), so:

var frame = document.getElementByID(“keith”).firstElementChild

That’s the iframe. From there, you may or may not be able to do:

var keith_doc = frame.contentDocument

… and then keith_doc.getSelection.toString() would (I believe) give you whatever is selected.

The PROBLEM THOUGH is that the src for the iframe is going to be from Google drive and cross-domain restrictions are going to stop you from getting contentDocument.

So, I don’t think you can successfully do this, but that’s how you’d do it…

Aside: the Google document viewer Api seems to have methods that do allow one to get the selection in the doc, so maybe just make the request of zeroqode?

#pluginsthatdontdoanything, amirite?

Keith,

I will try to get your new solution tonight. If I download the document reader and counter I can get all of the contexts for a document into a text box or in my database. Could I then search the highlighted text from the document viewer in the text box and return that value?

I will ask zeroqode but they told me to use both. The issue I have with document reader and counter is when the document is uploaded the format that is returned is just words and not the same format.

I will let you know what I find out. Thank you again for your time and ongoing help.

Very Respectfully,

Josh

Yeah, if you are parsing the document and then just displaying the text from it in a text element, the original idea will work.