Insert javascript in a page

General questions about CMSimple
cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: Insert javascript in a page

Post by cmb » Sat Oct 09, 2021 9:53 am

olape wrote:
Sat Oct 09, 2021 7:51 am
It will probably be because $hjs is already through at this point.
$hjs is valid for any plugin call on a page; it's only a problem if the plugin call is made from the template's body.
bastingse wrote:
Sat Oct 09, 2021 8:10 am
IT says to paste the code in the text where i want to show it.
Ah. Then you need to return:

Code: Select all

<?php

function myJs() {
    return '<link href="/1632923145_813/core/framework/libs/pj/css/pj.bootstrap.min.css" type="text/css" rel="stylesheet" />'
        . '<link href="/1632923145_813/index.php?controller=pjFront&action=pjActionLoadCss&id=10" type="text/css" rel="stylesheet" />'
        . '<script type="text/javascript" src="/1632923145_813/index.php?controller=pjFront&action=pjActionLoadJS"></script>'
        . '<script type="text/javascript" src="/1632923145_813/index.php?controller=pjFront&action=pjActionLoad&id=10"></script>';
}
Having Stylesheet-Links in the body isn't nice, so you could do the following as well:

Code: Select all

<?php

function myJs() {
    global $hjs;

    $hjs .= '<link href="/1632923145_813/core/framework/libs/pj/css/pj.bootstrap.min.css" type="text/css" rel="stylesheet" />'
        . '<link href="/1632923145_813/index.php?controller=pjFront&action=pjActionLoadCss&id=10" type="text/css" rel="stylesheet" />';
    return '<script type="text/javascript" src="/1632923145_813/index.php?controller=pjFront&action=pjActionLoadJS"></script>'
        . '<script type="text/javascript" src="/1632923145_813/index.php?controller=pjFront&action=pjActionLoad&id=10"></script>';
}
bastingse wrote:
Sat Oct 09, 2021 8:10 am
What do you mean with pre-defined element??
I mean that they might say that you can insert a HTML element with a certain ID (or something like that) somewhere on the page, for instance:

Code: Select all

<div id="poll_container"></div>
Christoph M. Becker – Plugins for CMSimple_XH

bastingse
Posts: 308
Joined: Fri Jun 06, 2008 9:38 pm
Location: Netherlands
Contact:

Re: Insert javascript in a page

Post by bastingse » Mon Oct 11, 2021 10:45 am

cmb wrote:
Sat Oct 09, 2021 9:53 am
Ah. Then you need to return:
Yeah!!! That did the trick. It works now!!!
However it works without stylesheet from the script itself :x

bastingse
Posts: 308
Joined: Fri Jun 06, 2008 9:38 pm
Location: Netherlands
Contact:

Re: Insert javascript in a page

Post by bastingse » Mon Oct 11, 2021 10:48 am

And with the code you gave (see below) it also works with the stylesheet itselfs!! Thanks folks. Much appreciated!!!

Code: Select all

<?php

function myJs() {
    return '<link href="/1632923145_813/core/framework/libs/pj/css/pj.bootstrap.min.css" type="text/css" rel="stylesheet" />'
        . '<link href="/1632923145_813/index.php?controller=pjFront&action=pjActionLoadCss&id=10" type="text/css" rel="stylesheet" />'
        . '<script type="text/javascript" src="/1632923145_813/index.php?controller=pjFront&action=pjActionLoadJS"></script>'
        . '<script type="text/javascript" src="/1632923145_813/index.php?controller=pjFront&action=pjActionLoad&id=10"></script>';
}

Post Reply