Script does not work with external host

Asked

Viewed 161 times

1

My script does not work with files hosted on exetrno host

My files are on that host:

How do I make them eja run in this script below?

 <script type="text/javascript">

var resizeOwnr = function(width, height)
{
    var  = $('');
    .css('width', width);
    .css('height', height);
}

$(function()
{
    function ()
    {
        var  = $('');
        if()
        {
            var flashvars = 
            {
                system : '',
                url : ''
            };
            var params = {};
            var attributes = {};

            params.allowscriptaccess = '';
            params.allowFullScreen = 'true';
            params.allowFullScreenInteractive = 'true';

            swfobject.embedSWF('', '', '640', '480', '11.2.0', '', flashvars, params, attributes);
        }
    }

    embed();
});

</script>

1 answer

1

For this you will need to use google api,

take a look at the documentation:

https://developers.google.com/picker/docs/

The google example itself:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <title>Google Picker Example</title>

    <script type="text/javascript">

    // The Browser API key obtained from the Google Developers Console.
    // Replace with your own Browser API key, or your own key.
    var developerKey = 'xxxxxxxYYYYYYYY-12345678';

    // The Client ID obtained from the Google Developers Console. Replace with your own Client ID.
    var clientId = "1234567890-abcdefghijklmnopqrstuvwxyz.apps.googleusercontent.com"

    // Replace with your own App ID. (Its the first number in your Client ID)
    var appId = "1234567890";

    // Scope to use to access user's Drive items.
    var scope = ['https://www.googleapis.com/auth/drive'];

    var pickerApiLoaded = false;
    var oauthToken;

    // Use the Google API Loader script to load the google.picker script.
    function loadPicker() {
      gapi.load('auth', {'callback': onAuthApiLoad});
      gapi.load('picker', {'callback': onPickerApiLoad});
    }

    function onAuthApiLoad() {
      window.gapi.auth.authorize(
          {
            'client_id': clientId,
            'scope': scope,
            'immediate': false
          },
          handleAuthResult);
    }

    function onPickerApiLoad() {
      pickerApiLoaded = true;
      createPicker();
    }

    function handleAuthResult(authResult) {
      if (authResult && !authResult.error) {
        oauthToken = authResult.access_token;
        createPicker();
      }
    }

    // Create and render a Picker object for searching images.
    function createPicker() {
      if (pickerApiLoaded && oauthToken) {
        var view = new google.picker.View(google.picker.ViewId.DOCS);
        view.setMimeTypes("image/png,image/jpeg,image/jpg");
        var picker = new google.picker.PickerBuilder()
            .enableFeature(google.picker.Feature.NAV_HIDDEN)
            .enableFeature(google.picker.Feature.MULTISELECT_ENABLED)
            .setAppId(appId)
            .setOAuthToken(oauthToken)
            .addView(view)
            .addView(new google.picker.DocsUploadView())
            .setDeveloperKey(developerKey)
            .setCallback(pickerCallback)
            .build();
         picker.setVisible(true);
      }
    }

    // A simple callback implementation.
    function pickerCallback(data) {
      if (data.action == google.picker.Action.PICKED) {
        var fileId = data.docs[0].id;
        alert('The user selected: ' + fileId);
      }
    }
    </script>
  </head>
  <body>
    <div id="result"></div>

    <!-- The Google API Loader script. -->
    <script type="text/javascript" src="https://apis.google.com/js/api.js?onload=loadPicker"></script>
  </body>
</html>

---------------------------EDIT-----------------------

As there had not understood the question I will leave the top for future queries of other users.

In your case dude, it is not possible to load the script the way you want, because when you provide a dynamic path like you are doing:

" url : '/swf/Robotech_-_The_Macross_Saga.zip'"

The code interprets that there is a folder on the same level as the root of your project or the file that is running depending on the architecture that calls "swf" and contains your file in it, but since your server is external, has no dynamic way to call it referencing its own code, understood?

When you pass the dynamic path, the reference is your file that is running.

  • I think the question was not understood, the host works if I leave the full path of the files in the script, it turns out I wanted to use half the way as it is in the script

  • Okay I misunderstood. I edited the answer.

  • Cannot add extra code by having the script search for the start of the folder path?

  • Not because it is not a folder "local" is an external one, you could leave this URL saved in a variable and use it to concatenate in ajax with the path, but I think it would be the same, maybe just to unify and not need to change in many places.

  • The goal would be if in case I have that server exchange need not edit the files, just changes the server folder

  • So it only works if it’s all local. but you can leave a variable with the part that would change for example var url = "www.seuhost.com.br"; hence you would use it in your entire code, so if you need to change the server, you would only change that variable and boom. there are N other possibilities, but none of the way you want it, would have to do something similar.

Show 1 more comment

Browser other questions tagged

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