[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to create a javascript snippet to place in a website?

Posted on 2009-02-11
14
Medium Priority
?
395 Views
Last Modified: 2013-11-07
I am using Visual Studio and or Dreamweaver to create some basic web pages (I am a beginner) and have noticed on several test sites that I am working on the abliltiy to embed a Javascript snippet in a page - that calls the HTML.  

What I am looking for is how do you create the src part of the file below?  I can use visual studio or Dreamweaver.   I do know VB, but not Java?

Any tutorials or suggestions?
<script language="javascript" src="http://yada..." type="text/javascript"></script>

Open in new window

0
Comment
Question by:rrowe68
14 Comments
 
LVL 33

Expert Comment

by:raterus
ID: 23614585
It's just a separate javascript file on your webserver somewhere.  You usually don't see an absolute URL here, but a relative path.  For instance, if you have a directory with your .html file in it, and you created a javascript file "myscripts.js" in the same directory, you would link like this.

<script language="javascript" src="myscripts.js" type="text/javascript"></script>

It's really no different than linking to other .html files on your webserver.
0
 
LVL 41

Expert Comment

by:HonorGod
ID: 23614609
The Javascript (not Java, by the way), in the specified location, or in the
specified file, is a collection of javascript statements.  So, it could be
something as simple as:

so,

<script src="yada.js" type="text/javascript"></script>

would be the same as:

<script src="yada.js" type="text/javascript">
function init() {
  alert( 'Hi' )
}
</script>

function init() {
  alert( 'Hi' )
}

Open in new window

0
 
LVL 16

Expert Comment

by:burakiewicz
ID: 23614610
with vb
ClientScript.RegisterClientScriptInclude("KeyName", "http://yada...")
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 41

Expert Comment

by:HonorGod
ID: 23614615
sorry, the second should have been:

<script type="text/javascript">
function init() {
  alert( 'Hi' )
}
</script>
0
 

Author Comment

by:rrowe68
ID: 23614699
Thanks.   I do not know javascript.    I want to create a small html page (like a panel) with Visual Studio that I can embed in another site (I could use an iframe).   But, would like to learn how to do this with the javascript example in the original post.     I know how to create the HTML that I want.   The question is how to I then create a script to place this HTML in another site?

Thanks again.
0
 
LVL 41

Expert Comment

by:HonorGod
ID: 23614800
What, exactly, do you mean when you say:

create a script to place this HTML in another site
0
 
LVL 41

Expert Comment

by:HonorGod
ID: 23614857
There are ways, in javascript, to completely manipulate the page on which the script is executing.  For example, the script could traverse the page description, and add, change, or delete individual document elements.

So, I'm not quite sure what it is you are trying to do.
0
 

Author Comment

by:rrowe68
ID: 23614898
Honorgod...

I have some HTML that I want to place in various sites.

I just want the javascript to return/echo some html like in this example...

"<p>Hello Everyone</p>"
"<p><img src="../mcdonaldsLogo.jpg" width="111" height="101" alt="test" /> </p>"

How would the script read?

<script src="myscript.js" type="text/javascript">
function init() {
--->  write or echo the HTML that I want
}
</script>

Then use a line like this to call it ....

<script language="javascript" src="myscripts.js" type="text/javascript"></script>



0
 
LVL 41

Expert Comment

by:HonorGod
ID: 23615072
ok, that's a good start.

Where on the page would you like this placed?
0
 

Author Comment

by:rrowe68
ID: 23615189
It is going to be different on different pages.   But always within the body tags...  I can adjust for that once I figure out how to generate the script.

Thanks for you help.
0
 
LVL 41

Expert Comment

by:HonorGod
ID: 23615214
Something like this perhaps?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Test</title>
<script type='text/javascript'>
  function insert( id ) {
    var ele = document.getElementById( id )
    if ( ele ) {
      ele.innerHTML = '<p>Hello Everyone</p><p><img src="../mcdonaldsLogo.jpg" width="111" height="101" alt="test" /></p>'
    } else {
      alert( 'Specified element not found.  id="' + id + '"' )
    }
  }
</script>
</head>
<body onload='insert("here")'>
<div id='here'>
</div>
</body>
</html>

Open in new window

0
 
LVL 41

Accepted Solution

by:
HonorGod earned 2000 total points
ID: 23615229
All you have to do is to locate the element after which you want the code
inserted, then assign the objectName.innerHTML value like shown above.
0
 

Author Comment

by:rrowe68
ID: 23615476
The example that I am trying to emulate is this...
<script language="javascript" src="http://www.getzee.com/ocmarathon/travel.js" type="text/javascript"></script>

I have this code embedded on a website and it works perfectly.   I can place it anywhere that I need it.

My question what is the code in the travel.js?  This travel.js is just an example that and I want to be able to create a variety of scripts.   Maybe I am in over my head, but was hoping to take a page that I created, wrap in in javascript and then use this type of line for other sites to call.

Thanks very much.
0
 
LVL 41

Expert Comment

by:HonorGod
ID: 23618651
You are very welcome.  Thank you for the grade & points.

Good luck & have a great day.
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses
Course of the Month18 days, 11 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question