Now this all works and the result webpage URL prints to id='ID1', but the big question is how do I use this resulting URL in another Javascript section as the src="?
For example:
<script src=WHATEVER WAS RETURNED TO ID NAVIGATION>
</script>
<script type="text/javascript">
function urldata(obj) {
//blank on purpose
//this basically prints out data from another script (which resides on myurl)
}
</script>
<script src="myurl">
</script>
So from this, basically (and I don't know how because I found this script online) the urldata function uses the data from myurl to return a result from function urldata.
Without seeing the scripts that you are talking about,
this is just a guess as to what your problem is...
Code:
<script type="text/javascript">
function myurl() {
var str = 'Data from your function';
return str;
}
</script>
<script type="text/javascript">
function urldata(obj) {
//blank on purpose
//this basically prints out data from another script (which resides on myurl)
alert(obj);
}
// test
var tmp = myurl();
urldata(tmp);
</script>
There is no reason for 2 <script type="text/javascript"> </script> tag pairs.
You only need the very first and very last tag.
This reminds me of that joke about copper wire being invented in Glasgow, Scotland in 1742 when Two jocks were witnessed fighting over a penny.
Getting to the erroneous code is often like that scenario a fight... or if you prefer the dentist scenario, teeth come out easier... Blood and Stone comes to mind.
What he needs to do is have an object created with the attributes required and then appending to the head of the document.
Code:
var scriptSrc = "path/to/file.js";
var scriptEle = document.createElement("script"); // a new <script> HTML tag
scriptEle.setAttribute("src", scriptSrc ); // src
scriptEle.setAttribute("type", "text/javascript"); // type="text/javascript"
var head = document.getElementsByTagName("head")[0]; // the <head>
head.appendChild(scriptEle); // append to head
Should do the trick.
We all have baggage to carry in life, unfortunately for me I always get the trolley with the wonky wheel...
Code:
Youre = {
STILL_not_getting_it:function(){
alert("YOU, the original poster / thread starter NEED to POST the code and NOT a LINK.");
},
MissingThePoint:function(msg){
alert("You're missing the point. " + msg);
}
}
Youre.STILL_not_getting_it();
...
What he needs to do is have an object created with the attributes required and then appending to the head of the document.
Code:
var scriptSrc = "path/to/file.js";
var scriptEle = document.createElement("script"); // a new <script> HTML tag
scriptEle.setAttribute("src", scriptSrc ); // src
scriptEle.setAttribute("type", "text/javascript"); // type="text/javascript"
var head = document.getElementsByTagName("head")[0]; // the <head>
head.appendChild(scriptEle); // append to head
Should do the trick.
The only time I have use that bit of code in the past was if I did not want to load a lengthy script unless there was an option to use it. I would leave the loading of the script out until the user's option selection required it to be loaded.
What benefit would that bit of code have over just loading the 'file.js' directly in the <head> section since the OP seems to be wanting to use it all the time?
I wouldn't know but I guess that the guy has some reason to back door a script.
We all have baggage to carry in life, unfortunately for me I always get the trolley with the wonky wheel...
Code:
Youre = {
STILL_not_getting_it:function(){
alert("YOU, the original poster / thread starter NEED to POST the code and NOT a LINK.");
},
MissingThePoint:function(msg){
alert("You're missing the point. " + msg);
}
}
Youre.STILL_not_getting_it();
Without seeing the scripts that you are talking about,
this is just a guess as to what your problem is...
Code:
<script type="text/javascript">
function myurl() {
var str = 'Data from your function';
return str;
}
</script>
<script type="text/javascript">
function urldata(obj) {
//blank on purpose
//this basically prints out data from another script (which resides on myurl)
alert(obj);
}
// test
var tmp = myurl();
urldata(tmp);
</script>
There is no reason for 2 <script type="text/javascript"> </script> tag pairs.
You only need the very first and very last tag.
Ok thanks...now if you can help me understand that I might be able to make this work (right now it isn't).
First question, how does functionurldata(obj) actually run? it seems to just run but other functions that are like test() have to be actually called...do they not? ie. onClick="myurl()"
Why is var tmp = myurl(); urdata(tmp); after the function? Is that just how scripts work?
So myurl() spits out a string via return str;, then this is turned into a variable called tmp which in turn is injected into urldata in replace of obj?
Sorry if I'm asking too many questions...need to understand it so I can make it work. Really appreciate your help/
The only time I have use that bit of code in the past was if I did not want to load a lengthy script unless there was an option to use it. I would leave the loading of the script out until the user's option selection required it to be loaded.
What benefit would that bit of code have over just loading the 'file.js' directly in the <head> section since the OP seems to be wanting to use it all the time?
I'm getting other 'script' from Twitter JSON (not someone else's .js script file, haha). I've already figured out how to gather the data I want from the JSON result but basically I want the Twitter API to return a JSON result dependent on the search criteria entered on my site...hence the incorporating of text boxes into the URL.
Ok thanks...now if you can help me understand that I might be able to make this work (right now it isn't).
First question, how does functionurldata(obj) actually run? it seems to just run but other functions that are like test() have to be actually called...do they not? ie. onClick="myurl()"
Why is var tmp = myurl(); urdata(tmp); after the function? Is that just how scripts work?
So myurl() spits out a string via return str;, then this is turned into a variable called tmp which in turn is injected into urldata in replace of obj?
Sorry if I'm asking too many questions...need to understand it so I can make it work. Really appreciate your help/
Comments are shown in RED
Code:
<script type="text/javascript">
function myurl() {
var str = 'Data from your function'; // variable created
return str; // returned to calling function
}
function urldata(obj) { // variable received as argument of the function
//blank on purpose
//this basically prints out data from another script (which resides on myurl)
alert(obj); // display variable contents passed to function
}
// test
var tmp = myurl(); // function called and returns a string put into tmp
urldata(tmp); // function called that prints an alert from the information received
</script>
I know nothing about TWITTER as I don't even have an account.
Any information I could give you on this topic would be worthless.
Bookmarks