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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

Javascript in new Page


Go to End


5 Posts   1370 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, 607 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, 63 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, 607 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.