Script src - leaving out http to catch https?

Discussion in 'JavaScript' started by NaSh123, Sep 20, 2011.

  1. #1
    I want to modify the code

    <script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script>
    PHP:
    to

    <script src="//connect.facebook.net/en_US/all.js#xfbml=1"></script>
    PHP:
    So it will automatically pick up if the current URL is https or http. Am I correct in that modification or would that break the page?
     
    NaSh123, Sep 20, 2011 IP
  2. webbdesigner

    webbdesigner Guest

    Messages:
    25
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Nice try, but no cigar. This is not how it works.Try this:
    var Host = (("https:" == document.location.protocol) ? "https://" : "http://");document.write(unescape("%3Cscript src='" + Host + "connect.facebook.net/en_US/all.js#xfbml=1' type='text/javascript'%3E%3C/script%3E"));
    HTML:
     
    Last edited: Sep 24, 2011
    webbdesigner, Sep 24, 2011 IP
  3. JohnnySchultz

    JohnnySchultz Peon

    Messages:
    277
    Likes Received:
    4
    Best Answers:
    7
    Trophy Points:
    0
    #3
    it will not load the script.. you should put http or https before the html gets rendered..
    maybe make a variable that will be the flag if you are using https or http.

    
    <script src="<?php echo $is_ssl?'https':'http'; ?>//connect.facebook.net/en_US/all.js#xfbml=1"></script>
    
    PHP:
     
    JohnnySchultz, Sep 26, 2011 IP
  4. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #4
    
    document.write(unescape(""));
    Code (markup):
    seems to work pretty well. (It's how Google's jQuery link works.)
     
    Rukbat, Sep 26, 2011 IP