473,406 Members | 2,220 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Embed the javascript file.

Hi, Dear guru,

I have a question on embed a javascript into the master page.

I put the following line
<link runat="server" type="text/javascript" href="~/column.js" />

under the head, but obviously, it's not called anywhere.
But if I put this line,
<script type="text/javascript" src="column.js"></script>, it worked.

But I think i have to use the first approach since the second approach
will use an absolute path, and won't resolve in other pages which
include the master page.

Is there anyway around this issue

Thanks for help.
Apr 13 '06 #1
2 1354
Here is how you can do it

define the <head> tag in the master page to be a server side control as
this :
<head runat="server">

Then in Page_Init event of master page add the following :
HtmlLink link = new HtmlLink();
link.Href = "~/column.js";
link.Attributes.Add("type", "text/javascript");
Page.Header.Controls.Add(link);

HTH !
--
Swanand Mokashi
Microsoft Certified Solution Developer (.NET) - Early Achiever
Microsoft Certified Application Developer (.NET)

http://www.dotnetgenerics.com/
DotNetGenerics.com -- anything and everything about Microsoft .NET
technology ...

http://www.swanandmokashi.com/
http://www.swanandmokashi.com/HomePage/WebServices/
Home of the Stock Quotes, Quote of the day and Horoscope web services
"Jianwei Sun" <js***********@gmail.com> wrote in message
news:um**************@TK2MSFTNGP02.phx.gbl...
Hi, Dear guru,

I have a question on embed a javascript into the master page.

I put the following line
<link runat="server" type="text/javascript" href="~/column.js" />

under the head, but obviously, it's not called anywhere.
But if I put this line,
<script type="text/javascript" src="column.js"></script>, it worked.

But I think i have to use the first approach since the second approach
will use an absolute path, and won't resolve in other pages which include
the master page.

Is there anyway around this issue

Thanks for help.

Apr 13 '06 #2
Thanks for the reply,

Here is what is generated in header section after implementing your
suggestions.
<link href="column.js" type="text/javascript" />

But it seems it's still not called, is that because my javascript is wrong.

[Javascript code ]

function setTall() {
if (document.getElementById) {
//Adjust the column height here....
}
}

window.onload = function() {
setTall();
}

window.onresize = function() {
setTall();
}

But if I uncomment this line, it works...

<script type="text/javascript" src="column.js"></script>
Any other suggestions, thanks.

Swanand Mokashi wrote:
Here is how you can do it

define the <head> tag in the master page to be a server side control as
this :
<head runat="server">

Then in Page_Init event of master page add the following :
HtmlLink link = new HtmlLink();
link.Href = "~/column.js";
link.Attributes.Add("type", "text/javascript");
Page.Header.Controls.Add(link);

HTH !

Apr 13 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Tony Sutton | last post by:
I have this following code in my html file: <object classid="clsid:166B1BCA-3F9C-11CF-8075-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#...
1
by: majestik | last post by:
Question, can I see an event in Javascript that tells me a video starts playing using the <embed src="file.wmv>. I stream the video, but there is a wait time and wanted to pop up a message telling...
3
by: abrtlt | last post by:
I would like to have a web page in which, when the user clicks on any of several specific elements, a specific audio file is played, without reloading the page. The specific audio file name is...
3
by: Anil Gupte | last post by:
I want to embed using an embed tag or object tag (like YouTube or others do) to embed a video file in a web page. I want to know if there is an event related to the video being done playing. Also...
2
polymorphic
by: polymorphic | last post by:
I am no longer good at Javascript and need help. I'm trying to embed pdf files in html then build some sort of navigation between the pdfs via the pdf numbered file name. I can generate the...
5
by: elbin | last post by:
Hello, first to say that I am a total beginner in Javascript but I know some programming (python in particular) and am able to understand methods/parameters and so on. Here's my problem: I am...
1
by: ShahzadMahmood | last post by:
I want to embed the following code in javascript function javascript function is written just after the object code, I want to replace the popup window code with this object code while the file name...
2
dream party
by: dream party | last post by:
Inserting a Flash (SWF, FLV) file into HTML web page is already an old and familiar thing to all of us. It is a rather non-flexible thing that just to edit some options in the template. However, I...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.