Just some sailboat
Just some sailboat

Reputation: 330

How can I get this value in javascript?

I'm working on a opera extension that will search for a specific element on the current page once clicked. But I'm lost and I don't know what to do since I'm a very beginner in html/js stuffs.

The value that I am trying to extract from the page source is:

<script type="text/javascript">        

      var DEFAULT_URL = '/test/files/db9594e7e810cccdceb2e4faae6339a8.pdf';        

</script>

What should I do to extract this kind of attribute value from a pdf viewer link's page source? Any help would be appreciated, thank you in advance.

Upvotes: 0

Views: 169

Answers (3)

Alterlife
Alterlife

Reputation: 6625

There must be a way to just access window variables from an opera extension... Can't you just access window.DEFAULT_URL since that variable has been set?

As an alternative, you should be able to parse it out manually. The code below will give you all the script tags:

document.querySelectorAll("script")

If you want to get the content of the first script tag, you should be able to do so with:

document.querySelectorAll("script")[0].innerHTML

Once you've got that, you should be able to parse and extract the URL that you need from it.

Upvotes: 1

yatin_burhmi
yatin_burhmi

Reputation: 11

If you are on the pdf page, you can extract the path from url using

var url = winfow.location.href;

This is what I understood from your question. Otherwise, please elaborate.

Upvotes: 0

vtiron2002
vtiron2002

Reputation: 11

If you are extracting from another file in the directory then try var DEFAULT_URL = require('/test/files/db9594e7e810cccdceb2e4faae6339a8.pdf')

Upvotes: 0

Related Questions