Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Retrieve javascript from external file, not using src
Old 01-07-2009, 04:36 PM Retrieve javascript from external file, not using src
RadGH's Avatar
Skilled Talker

Posts: 76
Name: Radley
Trades: 0
I'm trying to make a drop-down box with different RSS feeds so users can choose what news feed they want to view. I was originally using this tool to automatically build the structure of the news into my website:

http://commons.ucalgary.ca/feed2js/build.php

To integrate it how it is normally you would go

Code:
<script language="JavaScript" src="http://commons.ucalgary.ca/feed2js/feed2js.php?src=URLTHEYPROVIDEYOU" type="text/javascript"></script>
example: http://radgh.com/test.html

Now I'd like to be able to change these with a drop down menu between a few feeds. One way would be to load each feed in a hidden div and show the appropriate one, but I fear this would cause long load times for users on slow connections.

Is there a way to execute javascript from an external "src" while inside a javascript function, an "If else" statement. For example:

Code:
	function changeFeed(src) {
		if (src == "nytimes") {
			document.getElementById("newsbox").executeURL = "www.a url here.com";
		}
		if (src == "popurls") {
			document.getElementById("newsbox").executeURL = "www.a url here.com";
		}
	}
</script>
I thought AJAX would work well, but I don't think AJAX actually executes the data. Plus, I'm not very good with AJAX.
RadGH is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-07-2009, 04:42 PM Re: Retrieve javascript from external file, not using src
Insensus's Avatar
Ultra Talker

Posts: 487
Name: Mark Stegeman
Location: Netherlands, Europe
Trades: 0
I think AJAX is the way to go.
You'll just create a PHP file which returns the contents of a .js file and call it with AJAX.
Then try using eval().

There might be another way but I wouldn't know any.
__________________
<?php ($helpfull>0)?$talkupation++ : '';?>
Insensus is offline
Reply With Quote
View Public Profile
 
Old 01-07-2009, 10:55 PM Re: Retrieve javascript from external file, not using src
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
With jQuery, it's as simple as this:
Code:
$("#someid").getScript("/any/url.js", function() {
//callback goes here (what to do after script has executed)
});
I've looked at the code for how this is accomplished, and it doesn't use an eval(). Instead, jQuery creates a script tag and appends it to the <head> of the document. It is an AJAX function, btw, and needs an onreadystatechange event to wait for before appending the code.
__________________
Join me on
Please login or register to view this content. Registration is FREE

Last edited by wayfarer07; 01-07-2009 at 11:00 PM..
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Reply     « Reply to Retrieve javascript from external file, not using src
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.95521 seconds with 12 queries