Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

calling a url outside of javascript function??

Status
Not open for further replies.

elvizcat

Technical User
Joined
May 9, 2005
Messages
6
Location
GB
Hi peeps,

I need a little help if poss, because most of the website is flash, I am trying to place the google adwords conversion tracking code snippet into a function in the head, so that i can then call that fuction from the flash document and in turn generate lead if someone sends the request more info form, however as you will see from the code below, the second piece of javascript google supply has the url to the script on their server but I don;t know how to encapsulate this also into the function, as my knowledge of javascript only stretches to having a function inside of the javascript tags, I could i suppose place the url into the top /first piece of javascript, but again i'm guessing this would still be outside of my function, is there maybe a way of calling the url of that piece of script from inside the function???



<!-- Google Code for Lead Conversion Page -->
<script language="JavaScript" type="text/javascript">
<!--
function googleAdword(){
var google_conversion_id = **********;
var google_conversion_language = "en_GB";
var google_conversion_format = "1";
var google_conversion_color = "666666";
if (0) {
var google_conversion_value = 0;
}
var google_conversion_label = "Lead";
//-->
}
</script>
<script language="JavaScript" src="</script>
 
Read the terms & conditions. If you reuse or edit Google code, they might be displeased!

The external secript generates the URL (looking a bit like the line posted below) for a HTML page.


I do not know what you are trying to do: Does Flash support anything like an IFRAME?

Code:
function google_get_filename() {
  var validLangs = Array("da", "de", "en_US", "en_GB", "es", "fi",
                         "fr", "it", "ja", "ko", "nl", "no", "pt_BR", "sv",
                         "zh_CN", "zh_TW");
  var lang = window.google_conversion_language;
  if (lang) {
    for (var i=0; i < validLangs.length; i++) {
      if (validLangs[i] == lang) return lang + ".html";
    }
  }
  return "en_US.html";
}

function google_language_code() {
  var lang = window.google_conversion_language;
  if (!lang) return "";
  if (2 == lang.length) return "&hl=" + escape(lang);
  if (5 == lang.length) {
    return ("&hl=" + escape(lang.substring(0,2)) +
      "&gl=" + escape(lang.substring(3,5)));
  }
  return "";
}

function google_handle_conversion() {
  var w = window;

  if (w.google_conversion_snippets) {
    w.google_conversion_snippets = w.google_conversion_snippets + 1;
  } else {
    w.google_conversion_snippets = 1;
  }

  if (w.google_conversion_id) {
    var proto = w.location.protocol.toLowerCase();
    if ('http:' != proto && 'https:' != proto) {
      proto = 'http:';
    }
    var path = "/?";
    if (w.google_conversion_type == 'landing') {
      path = "/extclk?";
    }
    var url = proto +
              "//[URL unfurl="true"]www.googleadservices.com/pagead/conversion/"[/URL] + 
              escape(w.google_conversion_id) + path +
              "random=" + (new Date()).getTime();
    if (w.google_conversion_value) {
      url = url + "&value=" + escape(w.google_conversion_value);
    }
    if (w.google_conversion_label) {
      url = url + "&label=" + escape(w.google_conversion_label);
    }
    if (w.google_conversion_ad) {
      url = url + "&gad=" + w.google_conversion_ad;
    }
    if (w.google_conversion_key) {
      url = url + "&gkw=" + w.google_conversion_key;
    }
    if (w.google_conversion_mtc) {
      url = url + "&gmtc=" + w.google_conversion_mtc;
    }
    if (w.google_conversion_raw) {
      url = url + "&graw=" + w.google_conversion_raw;
    }
    if (w.google_conversion_domain) {
      url = url + "&dom=" + w.google_conversion_domain;
    }
    url = url + google_language_code();
    var link = proto + "//services.google.com/sitestats/" +
               google_get_filename() + "?cid=" + escape(w.google_conversion_id);   
    
    if (w.google_conversion_format == 0) {
      document.write('<a href="' + link + '" target="_blank">' +
                     ' <img border=0 height=27 width=135 src="'
                     + url + '"></a>');
    } else if (w.google_conversion_snippets > 1) {
      url = url + '&num=' + w.google_conversion_snippets;
      document.write('<i' + 'mg height="1" width="1" border="0" ' + 
                     'src="' + url + '" />');
    } else {
      url = url + '&fmt=' + w.google_conversion_format;
      if (w.google_conversion_color) {
	url = url + '&bg=' + w.google_conversion_color;
      }
      var width = 300;
      var height = 13;
      if (w.google_conversion_format == 2) {
	width = 200;
	height = 26;
      }
      document.write('<ifr' + 'ame' +
                     ' name="google_conversion_frame"' +
		     ' width="' + width + '"' +
		     ' height="' + height + '"' +
		     ' src="' + url + '"' +
		     ' frameborder="0"' +
                     ' marginwidth="0"' +
                     ' marginheight="0"' +
                     ' vspace="0"' +
                     ' hspace="0"' +
                     ' allowtransparency="true"' +
                     ' scrolling="no">');
      document.write('<i' + 'mg height="1" width="1" border="0" ' + 
                     'src="' + url + '&ifr' + 'ame=0"' +
                     ' />');
      document.write('</ifr' + 'ame>');
    }
  }

  w.google_conversion_id = null;
  w.google_conversion_value = null;
  w.google_conversion_label = null;
  w.google_conversion_language = null;
  w.google_conversion_format = null;
  w.google_conversion_color = null;
}

if (window.google_conversion_format == null) {
  google_conversion_format = 0;
} else if (window.google_conversion_format > 2 ||
           window.google_conversion_format < 0 ) {
  google_conversion_format = 1;
}


function google_get_param(url, param) {
  var i;
  var val;
  if ((i = url.indexOf("?" + param + "=")) > -1 ||
      (i = url.indexOf("?" + param.toUpperCase() + "=")) > -1 ||
      (i = url.indexOf("&" + param + "=")) > -1 ||
      (i = url.indexOf("&" + param.toUpperCase() + "=")) > -1) {
    val = url.substring(i + param.length + 2, url.length);
    if ((i = val.indexOf("&")) > -1) {
      val = val.substring(0, i);
    }
  }
  return val;
}

function google_get_domain(url) {
   if (url) {
     domain = url.match(".?://(www\.)?([^/:]+)");
     if (domain && domain.length >= 3) {
       return domain[2] ? domain[2] : '';
     }
   }
   return "";
}

if (window.google_conversion_type == 'landing') {
  var url = document.location + "";
  google_conversion_domain = document.domain + "";
  var ref = google_get_domain(document.referrer);
  if (ref && (ref.indexOf(google_conversion_domain) > -1 || 
              google_conversion_domain.indexOf(ref) > -1)) {
    url = "";
  }
  google_conversion_ad = google_get_param(url, "gad");
  if (window.google_conversion_ad) {
    (google_conversion_key = google_get_param(url, "gkw")) ||
    (google_conversion_key = google_get_param(url, "ovkey"));
    google_conversion_mtc = google_get_param(url, "ovmtc");
    google_conversion_raw = google_get_param(url, "ovraw");
  }
}

google_handle_conversion();

----------
Memoria mihi benigna erit qui eam perscribam
 
thanks for the post, however what i'm trying to do is in the text in my post!!
 
Your post is not clear to me.

You can show/hide the IFRAME generated by Google - would that help?

----------
Memoria mihi benigna erit qui eam perscribam
 
would you know how i might go about doing that??
 
I can certainly make a guestimate :)
Code:
function toggle(){
gadds = document.getElementsByName('google_conversion_frame')[0];

if (gf.style.display = 'none'){
  gadds.style.display = '';
  } else {
  gadds.style.display = 'none';
  }
}
Whether or not it works is down to your roll of the dice :D

----------
Memoria mihi benigna erit qui eam perscribam
 
Flaw spotted immediately! Replace with:

if (gadds.style.display=='none')

----------
Memoria mihi benigna erit qui eam perscribam
 
Oh, and the '' should be 'block'

I do know what I'm doing, honest! I just don't stop to read what I type [sadeyes]

----------
Memoria mihi benigna erit qui eam perscribam
 
Hey stormbind! I don't think I've seen you here in quite a while! Where have you been?

Adam

There are only 10 types of people in the world: Those who understand binary, and those who don't
 
I think you may have the wrong idea of what i'm trying to acheive, and that is, all i need to be able to is place the code snippet from google in a function in the head of the html page, that page also contains a flash file, from the flash file I can call the name of the function trigering the google code to simply send a message to the script, informing the script has been processed.

The bit I don't know is because some of the javascript has a url that is not inside the function (check top), I need to also be able to call this at the same time.

Any ideas
 
If you want to know when the adverts have finished loading..

Short answer: no can do

Long answer: Data inside the IFRAME is sandboxed. For privacy/security reasons, your website cannot share data with another website.

If you want to know when the adverts have failed to load..

You can test to see if the IFRAME exists, but if the user has JS disabled, odds are they will have Flash disabled too.

if (!document.getElementsByName('google_conversion_frame')[0]) ... ;

----------
Memoria mihi benigna erit qui eam perscribam
 
IT'S NOT AN ADVERT!! adwords are paid for ads on google, when someone searches for your specified keyword you ad appears in the right hand side of the site, they then click the ad which takes them to the website who paid for the ad, when they get to the site and say fill out a form to request a brochure, the piece of google text at the top of this post is inserted in that page to call back to google to say the person who clicked on your ad in the google page has now created a lead (Return On Investment)

But instead of the code being in the page(body) it's in the head, inside a function, a flash document resides in the page, inside flash is a button at the bottom of a form, when they press submit in flash, it calls the javascript in the head of the html page therefore triggering the function to call back to google.

I JUST DON'T KNOW HOW TO INCLUDE THE PIECE OF GOOGLE CODE INTO A FUCNTION, AS IF YOU LOOK AT THE CODE AT THE TOP YOU WILL SEE THE SECOND PIECE OF GOOGLE SCRIPT <JAVASCRIPT URL IS OUTSIDE OF THE FUNCTION.

my question is how do i include this in the function....

Please read what i have said...........
 
Assuming that you're doing some sort of web developing I feel that I can also assume that you're privy to the term "netiquite" and what it entails.

Using all caps to get your point across is considered by most people to be an act of shouting your point. Also, reminding us to "Please read what I have said........." kinda comes off as a "why don't you pay more attention" comment.

Surely you understand that we here at tek-tips are not paid to help you. We come here to help others like ourselves, so that they can learn and return the favor to other users in need of help. To shout at anyone who is helping you of their own free will certainly doesn't show any shred of professionalism. Perhaps you should knock your tone down a few levels if you expect to get any help here.

-kaht

...looks like you don't have a job, so why don't you get out there and feed Tina.
[banghead]
 
Thanks khat.

Functions in the external .js file are loaded as part of your page.

You can query all the functions and variables as though you had typed them into the head of your page yourself.

Source was posted so you can see whatever it is you are looking for.

For legal, privacy, and security reasons: You cannot simulate clicking an adwords link.

--Glen :)

Memoria mihi benigna erit qui eam perscribam
 
ok peeps just forgeti ever posted yeah,

Cause basically no-one has even attempted to offer a solution to a JAVASCRIPT FUNCTION ISSUE, that means it has nothing to do with google, as this code snippet happens without user intervention period.

and yes I was shouting because that what you tend to after repeating yourself 3 times with the same problem.......

 
and yes I was shouting because that what you tend to after repeating yourself 3 times with the same problem.......

Perhaps if you're a hothead. I don't think you got my point from earlier, let me reiterate:

We are not paid to help you. We get nothing from helping you besides the satisfaction of knowing that we've helped someone else solve their problem. So for you to come here and get pushy about your question and act like a whiney baby cause you're not getting the answer you're looking for just makes us sit back and laugh. You catch more bees with honey than vinegar.

You've shown that you're obviously not bright enough to realize that the portion of google's functions that you want to steal reside in the external javascript function that you are attempting to import. If there's one specific part of the google function that you want to use, why don't you just open up the .js file, find it, and copy/paste it into your function?

I can't imagine that this thread will stick around too much longer, so let me just say that I hope you enjoyed your extremely short stay here at Tek-tips, go take your anger somewhere else.

-kaht

...looks like you don't have a job, so why don't you get out there and feed Tina.
[banghead]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top