...

View Full Version : External .js file doesn't working,why?



puexine
11-15-2010, 01:48 PM
Here is a .js file to hack ie6,but it doesn't work when i put it out of the .html file.It can woking only in the .html file.


It's fine in the .html file. Below:


<html>
<head>
<script type="text/javascript">
sfHover =function() {
var sfEls = document.getElementById("nav").getElementsByTagName("LI");
for (var i=0; i<sfEls.length; i++) {
sfEls[i].onmouseover=function() {
this.className+=" sfhover";
}
sfEls[i].onmouseout=function() {
this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
}
}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);
</script>
</head>
<body>
......
......
</body>
</html>



It's not working if external .js file.below:


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

note:I haven't added the <script type="text/javascript">...<script> code to the .js file.

any help will be good.

Philip M
11-15-2010, 01:58 PM
If you are sure that there are no HTML tags in your file, check the file name and directory path........


All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

abduraooft
11-15-2010, 02:11 PM
any help will be goo Can we have a link to your page?

puexine
11-15-2010, 02:26 PM
nav、LI、sfhover are in the .CSS file.The file name and directory path are all correct.

abduraooft
11-15-2010, 02:49 PM
Could you please post your complete html,css,and js files?

puexine
11-15-2010, 03:07 PM
.css file:


#nav {
background:#3D3D3D;
height:32px;
padding:0px;
margin:0px;
width:100%;
z-index:10;
left:0px;
position:absolute;
}
#nav ul.menu{
left: 0px;
position:absolute;
display:block;
}
.menu li.top{
padding-top: 6px;
font-size: 11px;

}
.menu table {
border-collapse:collapse;
width:0;
height:0;
position:relative;
top:-1px;
left:-35px;
}
.menu .fly {
background: transparent url(style/arrow.gif) no-repeat right center;
right:0px;
position:relative;
}

/*-------- Suckerfish Menu */
#nav, #nav ul {
float:left;
list-style:none;
line-height:32px;
padding:0;
margin:0;
width:100%;
font-size: 11px;
}
#nav li {
position : relative;
float:left;
padding:0;
}
#nav li a {
width: 70px;
text-align:center;
display: block;
color: black;
text-decoration : none;
padding : 0px;
color:white;
}

#nav li ul {
position : absolute;
left: -999em;
margin-left: 0px;
margin-top: 0px;
}
#nav li ul ul {
margin-left : 70px;
margin-top : -32px;
}
#nav li ul ul ul {
line-height:33px\9;
}
#nav li a:hover {
color : black;
background-color : #a0a0a0;
}

#nav li:hover, #nav li.sfhover {
background: #a0a0a0;
}
#nav li:hover ul ul, #nav li:hover ul ul ul, #nav li:hover ul ul ul ul, #nav li.sfhover ul ul, #nav li.sfhover ul ul ul, #nav li.sfhover ul ul ul ul {
left: -999em;
}
#nav li:hover ul, #nav li li:hover ul, #nav li li li:hover ul, #nav li li li li:hover ul, #nav li.sfhover ul, #nav li li.sfhover ul, #nav li li li.sfhover ul, #nav li li li li.sfhover ul {
left: auto;
background-color : #ccc;
width: 70px;
}


.js file:

sfHover =function() {
var sfEls = document.getElementById("nav").getElementsByTagName("LI");
for (var i=0; i<sfEls.length; i++) {
sfEls[i].onmouseover=function() {
this.className+=" sfhover";
}
sfEls[i].onmouseout=function() {
this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
}
}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);


site.master file:

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="site.master.cs" Inherits="StandardSite" %>
<%@ Register Src="~/User controls/MenuControl.ascx" TagName="MenuControl" TagPrefix="uc2" %>
<%@ Import Namespace="BlogEngine.Core" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head runat="server" profile="http://gmpg.org/xfn/11">

<script type="text/javascript" src="~/themes/standard/style/suckerfish.js"></script>
<link rel="stylesheet" href="~/themes/standard/style/wrap.css" type="text/css" />
<link rel="shortcut icon" href="~/pics/" type="image/x-icon"/>

</head>
<body>

<div id="header">
<p><a href="<%=Utils.AbsoluteWebRoot %>"><%=BlogSettings.Instance.Name %></a></p>
<span><%=BlogSettings.Instance.Description %></span>
</div>

<div id="nav">
<uc2:MenuControl ID="MenuControl" runat="server"
MinutesToRefresh="0"
SortBy="Title"
OrderDirection="Descending"
ShowArchivePage="True"
ShowContactPage="True"
ShowSearchPage="True"
ShowCategoriesAcross="True"
ShowGalleryPage="True"
GalleryPageText="Photogallery"
ShowHomePage="True"
ShowCategoriesPage="True"
ArchivePageText="archive"
ContactPageText="contact"
AdministrationText="admin"
HomePageText="home"
CategoriesPageText="Editorials"
SearchPageText="search"/>
</div>

<form runat="Server" class="body">

<div id="content">
<blog:SearchOnSearch runat="server" MaxResults="3" Headline="You searched for" Text="Here are some results for the search term on this website" />
<asp:ContentPlaceHolder ID="cphBody" runat="server" />

<p id="footer">
Powered by <a href="http://www.dotnetblogengine.net">BlogEngine.NET</a> <%=BlogSettings.Instance.Version() %><br />
Theme by <a href="http://blog.madskristensen.dk">Mads Kristensen</a>
</p>
</div>

<div id="sidepanel">
<blog:WidgetZone runat="server" ZoneName="be_WIDGET_ZONE" />
<a runat="server" id="aLogin" />
</div>

</form>

</body>
</html>

abduraooft
11-15-2010, 03:16 PM
site.master file: Pots the parsed HTML output taken from browser's "view source" option

puexine
11-15-2010, 03:19 PM
here:http://nuanxi.com/default.aspx

abduraooft
11-15-2010, 04:20 PM
<script type="text/javascript" src="~/themes/standard/style/suckerfish.js"></script> Remove that ~ from there to correct the reference.

puexine
11-16-2010, 05:14 AM
yes,so beautiful!! thanks in advance!

but there is still a problem,why .css file is fine?


<script type="text/javascript" src="/themes/standard/style/suckerfish.js"></script>
<link rel="stylesheet" href="~/themes/standard/style/wrap.css" type="text/css" />



thanks



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum