en:user:gs3_sample_format_statements
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
en:user:gs3_sample_format_statements [2016/10/09 23:26] – [Adding javascript into a page] kjdon | en:user:gs3_sample_format_statements [2016/10/12 21:47] – can't use innerHTML if the element already has content kjdon | ||
---|---|---|---|
Line 276: | Line 276: | ||
* **single page, single collection** | * **single page, single collection** | ||
- | * | + | |
Say you just want to use this new javascript on the classifier pages, then add the template into the main classifier format element. Or add it into the format element of a specific classifier and it will only be available for that single classifier. | Say you just want to use this new javascript on the classifier pages, then add the template into the main classifier format element. Or add it into the format element of a specific classifier and it will only be available for that single classifier. | ||
Line 312: | Line 312: | ||
</ | </ | ||
- | This lets us check that our function is correct and we are getting the right metadata. However, using " | + | This lets us check that our function is correct and we are getting the right metadata. However, using " |
- | Instead, we will need to set the innerHTML | + | Instead, we will need to add to the html of the td element. This means we need to give the td element an id so we can find it again. |
+ | If the <td> we are adding the filesize to contains only the filesize, then we can use the element.innerHTML() method to set the content. | ||
< | < | ||
<td> | <td> | ||
Line 321: | Line 322: | ||
<script type=" | <script type=" | ||
document.getElementById(< | document.getElementById(< | ||
+ | </ | ||
+ | </td> | ||
+ | </ | ||
+ | |||
+ | However, if this <td> element already has content, then we need to append the filesize, using element.appendChild() and document.createTextNode(). For example: | ||
+ | |||
+ | < | ||
+ | <td> | ||
+ | < | ||
+ | ...other content here... | ||
+ | <script type=" | ||
+ | document.getElementById(< | ||
</ | </ | ||
</td> | </td> | ||
Line 332: | Line 345: | ||
We set the text to be the result of calling our function on the filesize metadata. | We set the text to be the result of calling our function on the filesize metadata. | ||
+ | |||
+ | To add to an element' | ||
One further tricky part. We want to write **document.getElementById("< | One further tricky part. We want to write **document.getElementById("< | ||
- | i.e. **document.getElementById(< | + | i.e. **document.getElementById(< |
- | ** | + | |
Greenstone provides a shorthand: **< | Greenstone provides a shorthand: **< | ||
en/user/gs3_sample_format_statements.txt · Last modified: 2023/03/13 01:46 by 127.0.0.1