Execute <script> during runtime.

B

batham

Hi Gurus,

How can I execute a script during runtime. Here is my code, so how do I
execute the new script during runtime which should be a part of the
'topDiv'.

Thanks Help is appreciated.
- Shailendra

------- CODE ----------------

<html>
<title></title>
<script>

function GetNew() {
document.getElementById('topDiv').innerHTML = '';
var scElement = document.createElement('script');
scElement.id = 'NewScript1';
scElement.language = 'javascript';
scElement.type = 'text/javascript';
scElement.src = 'http://somenewwebpagewhichreturnshtml.com'; //
This web page returns HTML using document.write('somehtml code') or
returns a flash JS code.
document.getElementById('topDiv').appendChild(scElement);
}
</script>
<body>
<div id='topDiv'>
<script id='Script1'
src='http://somewebpagewhichreturnshtml.com'></script>
</div>
<input id="Button1" type="button" value="Get New HTML"
onclick="GetNew();" />
</body>
</html>
 
G

gimme_this_gimme_that

This will get you started.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1"/>
<title></title>
<script type="text/javascript">
<!--

var nav = "nav1";

function SwapNav() {
document.all.nav.style.display ='none';
var elem = document.getElementById("nav");
var root = document.documentElement;
("nav1" == nav) ? Nav1() : Nav2();
document.all.nav.style.display ='';
}

function Nav1() {
document.all.nav.innerHTML =
document.getElementById("nav1").innerHTML;
nav = "nav2";
}

function Nav2() {
document.all.nav.innerHTML =
document.getElementById("nav2").innerHTML;
nav = "nav1";
}

//-->
</script>

<div id="nav"></div>
<input type="button" onclick="SwapNav()" value="Swap"/>

<!-- start navs here -->

<div style="position:absolute;visibility:hidden;background:#FFFFFF;">


<div id="nav1" >
<table border="1" width="350" bgcolor="#FFFFFF">
<tr><td bgcolor="#CCDCF2"><p>Nav #1</p></td>
</tr>
<tr>
<td>asf af asdfas afsd fasdfasfadfa
</td>
</tr>
</table>
</div>

<div id="nav2" >
<table border="1" width="350" bgcolor="#FFFFFF">
<tr><td bgcolor="#CCDCF2"><p>Nav #2</p></td>
</tr>
<tr>
<td>n asdf asdf asdf asdf asfasdf af asdfadf asdf asfa fasf adfa fsfad
</td>
</tr>
</table>
</div>

</div>
<script>Nav1()</script>
</body>
</html>
 
G

gimme_this_gimme_that

Thanks Randy. Let batham be the judge of the usefulness of the code.
Aside from that, I was the only person kind enough to provide batham
suggestions.

The code shows how he can swap out navigation. All he has to do is swap
out the
contents of the div with "navigation html". I say get started because
additional
Javascript is required to actually fill the div tags with content from
the other
sites rather than from hard coded values.

Randy, has it occurred to you that the bitterness that is notable in
your posts
might impact your chances of someday finding a job? That is, assuming
you care
enough about JavascriptToolbox to refer to it in a resume.

I can't speak for places out side the US, especially Wonderful
California,
but here responses like yours seem pointless and borderline idiotic.
 
B

batham

thanks gimme gimme, your code sure works fine, but not what I want, I
need to dynamically or shall i say during runtime load a script which
points to a HTTP and does some magic sh$t.

I did get a working version but the calling script is so F$cked up
that it has a script within a script and another script, lets just say
people drink while they program LOL.

Anyways randy relax dude, he was just "trying" to help dude, I don't
know where you guys are at, but southern california sure rocks dude.

take it easy
shailendra batham
 
G

gimme_this_gimme_that

Well... Does the site you're trying to scrape have an RSS version of
the page you want?

If it does, review a few of the AJAX examples on the internet that use
XMLHttpRequest.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top