Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New to the CF scene
    Join Date
    Aug 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Minor Help Needed With Yelp Javascript

    Hi i am very familiar with html and css however javascript even the simplest form i have no clue , maybe it is time i start learning it.

    Yelp ( the review site ) www.yelp.com gives businesses options to add "review badges" on the business's website. the code sippets are fine however, when added and clicked on, it does not open the yelp profile link in a new page ( kind of like target="_blank" in html). Does anybody know how to fix the code to make it the link open in a page and not on the same page?

    My website is a wordpress theme "infocus" it gives me the option to add custom javascript of the page level too. Below is the code

    Thank you very much in advance

    Code:
    <div id="yelp-biz-badge-rrc-0Lqe582q6_Vb5nrXAADPPg"><a href="http://www.yelp.com/biz/ez-choice-financial-credit-repair-irvine">Check out EZ Choice Financial Credit Repair on Yelp</a></div><script type="text/javascript">(function(d, t) {var g = d.createElement(t);var s = d.getElementsByTagName(t)[0];g.id = "yelp-biz-badge-script-rrc-0Lqe582q6_Vb5nrXAADPPg";g.src = "//dyn.yelpcdn.com/biz_badge_js/en_US/rrc/0Lqe582q6_Vb5nrXAADPPg.js";s.parentNode.insertBefore(g, s);}(document, 'script'));</script>

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,986
    Thanks
    79
    Thanked 4,432 Times in 4,397 Posts
    That code is creating a <script> tag and then pointing its src= attribute to //dyn.yelpcdn.com/biz_badge_js/en_US/rrc/0Lqe582q6_Vb5nrXAADPPg.js

    That JS, in turn, is creating the badge.

    So you would need to use your browsers debugger (hit the F12 key) to investigate what the then created badge looks like once it is part of the HTML. At that point, you should be able to do something to add a target= or equivalent.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,986
    Thanks
    79
    Thanked 4,432 Times in 4,397 Posts
    Actually, it looks like it is dirt simple.

    The JS file I noted above produces this JS code:
    Code:
    var badge_element = document.getElementById("yelp-biz-badge-rrc-0Lqe582q6_Vb5nrXAADPPg");
        badge_element.innerHTML = "\u003ca href=\"http://www.yelp.com/biz/ez-choice-financial-credit-repair-irvine\"\u003e\u003cimg alt=\"EZ Choice Financial Credit Repair\" src=\"http://dyn.yelpcdn.com/extimg/en_US/rrc/0Lqe582q6_Vb5nrXAADPPg.png\" height=\"55\" width=\"125\"\u003e\u003c/a\u003e";
    So all you would need to do would be something like
    Code:
    document.getElementById("yelp-biz-badge-rrc-0Lqe582q6_Vb5nrXAADPPg").getElementsByTagName("a")[0].target="_blank";
    Just guessing, but seems close at the very least.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #4
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,981
    Thanks
    56
    Thanked 557 Times in 554 Posts
    erm... why not just add the target="_blank" to the a tag?
    Code:
    <div id="yelp-biz-badge-rrc-0Lqe582q6_Vb5nrXAADPPg"><a target="_blank" href="http://www.yelp.com/biz/ez-choice-financial-credit-repair-irvine">Check out EZ Choice Financial Credit Repair on Yelp</a></div><script type="text/javascript">(function(d, t) {var g = d.createElement(t);var s = d.getElementsByTagName(t)[0];g.id = "yelp-biz-badge-script-rrc-0Lqe582q6_Vb5nrXAADPPg";g.src = "//dyn.yelpcdn.com/biz_badge_js/en_US/rrc/0Lqe582q6_Vb5nrXAADPPg.js";s.parentNode.insertBefore(g, s);}(document, 'script'));</script>

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,986
    Thanks
    79
    Thanked 4,432 Times in 4,397 Posts
    Well, heck. I didn't even notice they were the same URL.

    But won't the JS code overwrite the contents of the <div> and thus lose the target=???
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #6
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,981
    Thanks
    56
    Thanked 557 Times in 554 Posts
    nope.

  • #7
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,986
    Thanks
    79
    Thanked 4,432 Times in 4,397 Posts
    Okay, I give up. Why not? The original HTML as you would modify it:
    Code:
    <div id="yelp-biz-badge-rrc-0Lqe582q6_Vb5nrXAADPPg">
    <a href="http://www.yelp.com/biz/ez-choice-financial-credit-repair-irvine" target="_blank">
    The JavaScript code as dynamically loaded (and invoked):
    Code:
    var badge_element = document.getElementById("yelp-biz-badge-rrc-0Lqe582q6_Vb5nrXAADPPg"); // note same element
    badge_element.innerHTML = "<a href=\"http://www.yelp.com/biz/ez-choice-financial-credit-repair-irvine\">  ...."
    If that doesn't wipe out the _target, why not?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #8
    New to the CF scene
    Join Date
    Aug 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    adding target="_blank" doesn't work i already have tried it before posting here asking for help

  • #9
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,981
    Thanks
    56
    Thanked 557 Times in 554 Posts
    Ah, sorry -when I tested it, it worked. have you tried old pedant's suggestion?

  • #10
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,986
    Thanks
    79
    Thanked 4,432 Times in 4,397 Posts
    You should add the target=_blank in both places: In the original HTML and then also in the JS code, the way I showed.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #11
    New Coder
    Join Date
    Aug 2014
    Posts
    27
    Thanks
    0
    Thanked 1 Time in 1 Post
    please look at the yelp library you are trying to utilize. It is made for use with Node.js. Basically you can't just take a library created for use with Node.js and load it with RequireJS


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •