Loading...
 
Skip to main content

Features / Usability


Can't insert javascript

I want to insert the following javascript into a page:

function showProducts() {
document.getElementById('menu42__1271').style.display='block';
setTimeout("getElementById('menu42__1273').style.display='block'",1000);
}

I've installed the javacript plugin, js.

I've tried doing what the documentation says and surrounding the code with these tags:

(open curly bracket)JS()(close curly bracket)
//code here
(open curly bracket)JS(close curly bracket)

(I can't seem to embed these tags in a reply on this forum, hence the curly bracket things above)

This produces the following error when I save the page:

An error occured in a database query!

Context:
File tiki-index.php
Url tiki-index.php?page=HomePage
Query:
INSERT INTO tiki_plugin_security (fingerprint, status, added_by, last_objectType, last_objectId) VALUES(?, ?, ?, ?, ?)
Values:
0 js-28cb81ce60a35eb62e7d94537f8d1aa5-0df3f8fa6a273b5283894cce2d1e8455-180000-200000
1 pending
2 admin
3 wiki page
4 HomePage
Message:
Built query was probably:
INSERT INTO tiki_plugin_security (fingerprint, status, added_by, last_objectType, last_objectId) VALUES('js-28cb81ce60a35eb62e7d94537f8d1aa5-0df3f8fa6a273b5283894cce2d1e8455-180000-200000', 'pending', 'admin', 'wiki page', 'HomePage')

I've tried taking out all the code and just inserting those {JS} tags but the error still persists, so I know it's not an error in my javascript.

I've tried searching the forum and found another syntax for surrounding the code:

(script type="text/javascript")
//code here
(/script)

That just results in the javascript code being rendered in full view on the page.

Any help would be appreciated.

I think I responded to the other page, but I didn't see a mention of your using the JS plugin.

How I bypass these "security features" is to include a *.js file with your functions in the templates/head.tpl file. I suggest naming the js file the same as the page that it's going to be used for, or the process that it's functions are primarily used for.


Incidentally, it isn't normal to get a database error when using the JS plugin or any other plugin. I did a test in a Tiki 3.2 site, using the plugin and the "function showProducts()" lines and then checked the page source. HTML script tags were inserted around the lines. If this problem has persisted, probably the database needs to be updated.

-- Gary