Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Javascript in new Page


Reply


5 Posts   451 Views

Avatar
Samy

Community Member, 2 Posts

24 March 2014 at 9:19am

Hello people.

Im here to report a problem or to get some help to understand how to use javascript code in a new page.

I put my code in html page:
<img src="/image.gif" onclick="startGateway('155891');" />

And this under the html code.
<script type="text/javascript" src="/gateway/mygate.php?id=4e2b7a3945426d416d786c7542355776"></script>

But when i save and publish my site and i go in the page and click the image, i do not see any script opening.

PS: I got this problem with AdSense script too.

Thanks

Avatar
Double-A-Ron

Community Member, 604 Posts

25 March 2014 at 9:17pm

You'll have to explain how you are putting this in your page. In the template? In a content window in the CMS admin?

The latter isn't really the place for this as TinyMCE will strip certain tags out when you save as a security measure. There are ways to allow it in code. But if this is your site, what you are doing here is better off in the template.

What does the source code of this section end up looking like on the frontend?

Avatar
Samy

Community Member, 2 Posts

26 March 2014 at 1:29am

I put the code on content window in the CMS admin page. The source of this code open a table where you have to complete a survey.

How can i allow this code, or where i have to put it if i want to use it in pages?

Avatar
nzstephenf

Community Member, 34 Posts

27 March 2014 at 12:44am

Maybe try using jQuery? This will also allow you to modify any script changes on the external javascript file rather than on individual items like /image.gif :)

Avatar
Double-A-Ron

Community Member, 604 Posts

27 March 2014 at 6:38am

Is there any reason why you are not putting this into your template file?

The HTML Editor window is not really the place for JavaScript unless you extend it. It strips out some HTML tags because giving users the ability to inject JavaScript is a security concern.

If you want to allow JavaScript to be entered into the editor, you'll need to search for TinyMCE. That's what the editor is and it's a third party app.