Links in javascript

Asked

Viewed 70 times

0

Good morning guys, I’m having a problem calling a link in javascript, in php I have a rule where every time I put #URL#link.... it replaces with the server address. Example #URL#public it replaces for http://localhost/public, in javascript I could not make it work. If anyone can give me a hand, I’ll put my rule in php, and below the javascript where I need to adjust.

php.config

date_default_timezone_set('America/Sao_Paulo');
error_reporting(E_ALL);
ini_set('display_errors',true);
define('URL','http://'.$_SERVER['HTTP_HOST'].'/sistema/');
define('DS', DIRECTORY_SEPARATOR);
define('PATH', getcwd().DS );
define('TEMPLATE', PATH.'view'.DS.'template.html');

Javascript that needs to be adjusted

CKEDITOR.editorConfig = function(config) {
    config.filebrowserBrowseUrl = '#URL#sistema/public/plugin/ckeditor/kcfinder/browse.php';
    config.filebrowserImageBrowseUrl = '#URL#sistema/public/plugin/ckeditor/kcfinder/browse.php?type=images';
    config.filebrowserFlashBrowseUrl = '#URL#sistema/public/plugin/ckeditor/kcfinder/browse.php?type=flash';
    config.filebrowserUploadUrl = '#URL#sistema/public/plugin/ckeditor/kcfinder/upload.php?type=files';
    config.filebrowserImageUploadUrl = '#URL#sistema/public/plugin/ckeditor/kcfinder/upload.php?type=images';
    config.filebrowserFlashUploadUrl = '#URL#sistema/public/plugin/ckeditor/kcfinder/upload.php?type=flash';
};

2 answers

1

On the page where you load the Ckeditor script, put this

<script type="text/javascript">
ckeditor_global_url = <?php echo URL;?>;
</script>

Any other script that uses an equal name variable may conflict. So in this example we use a name that would hardly collide with another in use.

Something more elegant and "secure" would apply namespace, but the example would become more complicated. If you’re interested in improving your scripts, look for object-oriented javascript.

Anyway, in the Ckeditor script, I’d switch to that:

CKEDITOR.editorConfig = function(config) {
    config.baseHref = ckeditor_global_url;
    config.filebrowserBrowseUrl = 'public/plugin/ckeditor/kcfinder/browse.php';
    config.filebrowserImageBrowseUrl = 'public/plugin/ckeditor/kcfinder/browse.php?type=images';
    config.filebrowserFlashBrowseUrl = 'public/plugin/ckeditor/kcfinder/browse.php?type=flash';
    config.filebrowserUploadUrl = 'public/plugin/ckeditor/kcfinder/upload.php?type=files';
    config.filebrowserImageUploadUrl = 'public/plugin/ckeditor/kcfinder/upload.php?type=images';
    config.filebrowserFlashUploadUrl = 'public/plugin/ckeditor/kcfinder/upload.php?type=flash';
};

Here we only set a value for the property config.baseHref.

Finally, there are different ways to solve it. As he did not give many details of how his pages are, what the circumstances, etc., it is impossible to palpitate which way best or at least which way is most appropriate for his case.

  • This method I could not adapt. So I tried and I managed to fix it. Thank you.

0


I managed to solve it that way.

CKEDITOR.editorConfig = function(config) {
        config.filebrowserBrowseUrl = url+'public/plugin/ckeditor/kcfinder/browse.php';
        config.filebrowserImageBrowseUrl = url+'public/plugin/ckeditor/kcfinder/browse.php?type=images';
        config.filebrowserFlashBrowseUrl = url+'public/plugin/ckeditor/kcfinder/browse.php?type=flash';
        config.filebrowserUploadUrl = url+'public/plugin/ckeditor/kcfinder/upload.php?type=files';
        config.filebrowserImageUploadUrl = url+'public/plugin/ckeditor/kcfinder/upload.php?type=images';
        config.filebrowserFlashUploadUrl = url+'public/plugin/ckeditor/kcfinder/upload.php?type=flash';
    };

Browser other questions tagged

You are not signed in. Login or sign up in order to post.