/    Sign up×
Community /Pin to ProfileBookmark

onclick pass url and execute remote script problem

Hello all,

I have a menu system that I want to be able to onclick pass a url to a <script></script> (located in the main content of the page) where the url passed replaces the ‘src’ of that script.
The reason is because a lot of the links are syndicated content, and instead of having 10 or 20 extra pages just to load that content, I want to dynamically change the script src.
I don’t think it’s passing my variable because it’s a url or something.

Help please?

code:

<!–script that does all the work–>
<script type=”text/javascript”>
function synchange(pass)
{
var new_var = pass;
document.getElementById(“cursyncon”).setAttribute(“src”, new_var);
}
</script>

<!–menu part that activates the onclick and function, thus changing the content–>
<li><a href=”#” onclick=”synchange(‘http://content.cdsbe.com/_utility/ibmrdr/www.live.hal.webcollage.net/server/yorel/hal-showcase?ws-entry=halsrv-i-series-landing-page’)”>System i</a></li>

<!–goes in the main content junk where syndicated content shows up–>
<script id=”cursyncon” src=”#”></script>

thanks again for any help…!

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@scrubdevauthorJun 04.2010 — bump. if any insight, I would be very grateful...
Copy linkTweet thisAlerts:
@mrhooJun 04.2010 — It doesn't matter [B]where [/B]you put a script tag, if you insert it after the page has loaded.

Replacing or removing a script element does not remove any loaded script, it just adds the script from the new source to the global object. The original script is still in existence, though the new code may overwrite or break it.

You can add a new script element, but you cannot call any of its functions or use any of its objects until it is loaded and interpreted. You can use the script elements onload or readystatechange event, or use a timer to check for some property set in the script. If the script was on your own domain you could fetch it and run a callback with Ajax.
Copy linkTweet thisAlerts:
@scrubdevauthorJun 04.2010 — thank you very much, I will look into those other ideas.
×

Success!

Help @scrubdev spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...