Reputation: 143
I am trying to fix the problem that I am facing with JQuery LavaLamp Menu Bar in my website by adding the following bunch of code suggested by one of the amazing developers and people in this community:
<script>
if ($.browser.version < 9.0 && $.browser.msie) {
document.getElementsByTagName("head")[0].innerHTML = '<script type="text/javascript" src="./Scripts/jquery.easing.1.1.js"></script><script type="text/javascript" src="./Scripts/jquery.preloader.js"></script><script type="text/javascript" src="./Scripts/jquery.lavalamp.js"></script><script type="text/javascript" src="./Scripts/lavalamp-config.js"></script>';
}
else {
document.getElementById("head")[0].innerHTML = '<script type="text/javascript" src="./Scripts/jquery.easing.1.1.js"></script><script type="text/javascript" src="./Scripts/jquery.preloader.js">';
}
</script>
And in the Visual Studio 2010, I got the following error
Unterminated string constant
under the following line:
document.getElementsByTagName("head")[0].innerHTML = '<script type="text/javascript" src="./Scripts/jquery.easing.1.1.js"></script><script type="text/javascript" src="./Scripts/jquery.preloader.js"></script><script type="text/javascript" src="./Scripts/jquery.lavalamp.js"></script><script type="text/javascript" src="./Scripts/lavalamp-config.js"></script>';
So how I can fix this problem?
UPDATE #1:
I updated my code to what you suggested guys and I am still getting the same error. Also, here's a snapshot of the error:
UPDATE #2 I modified my code to let the Master Page includes the following code and I am still getting the same error that shows at the top of the page as shown in the above snapshot.
<head>
<script type="text/javascript">
function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
var rv = -1; // Return value assumes failure.
if (navigator.appName == 'Microsoft Internet Explorer') {
var ua = navigator.userAgent;
var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
if (re.exec(ua) != null)
rv = parseFloat(RegExp.$1);
}
return rv;
}
</script>
<script type="text/javascript">
if (getInternetExplorerVersion() < 9.0 && browser_type = "Microsoft Internet Explorer") {
document.getElementsByTagName("head")[0].innerHTML = "<script type='text/javascript' src='./Scripts/jquery.easing.1.1.js'></script><script type='text/javascript' src='./Scripts/jquery.preloader.js'></script><script type='text/javascript' src='./Scripts/jquery.lavalamp.js'></script><script type='text/javascript' src='./Scripts/lavalamp-config.js'></script>";
} else {
document.getElementById("head")[0].innerHTML = "<script type='text/javascript' src='./Scripts/jquery.easing.1.1.js'></script><script type='text/javascript' src='./Scripts/jquery.preloader.js'>";
}
</script>
</head>
Upvotes: 0
Views: 1617
Reputation: 150070
The closing script tags are likely being interpreted by the browser as the end of the current script block even though they're inside a string literal, which in turn means that particular string literal is unterminated.
Within your string, instead of
'</script>'
You can do
'<\/script>'
(When the JS runs the backslash is ignored.) Or sometimes you see something like:
'<' + '/script>'
Or replace the <
with the equivalent character code:
'\x3C/script>'
Upvotes: 1
Reputation: 93
Try this, Use the below function to get the browser version number
function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
var rv = -1; // Return value assumes failure.
if (navigator.appName == 'Microsoft Internet Explorer') {
var ua = navigator.userAgent;
var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
if (re.exec(ua) != null)
rv = parseFloat(RegExp.$1);
}
return rv;
}
and below for getting the browser name
var browser_type = navigator.appName ("Microsoft Internet Explorer")
so your new function would look like
if (getInternetExplorerVersion() < 9.0 && browser_type = "Microsoft Internet Explorer") {
document.getElementsByTagName("head")[0].innerHTML = "<script type='text/javascript' src='./Scripts/jquery.easing.1.1.js'></script><script type='text/javascript' src='./Scripts/jquery.preloader.js'></script><script type='text/javascript' src='./Scripts/jquery.lavalamp.js'></script><script type='text/javascript' src='./Scripts/lavalamp-config.js'></script>";
} else {
document.getElementById("head")[0].innerHTML = "<script type='text/javascript' src='./Scripts/jquery.easing.1.1.js'></script><script type='text/javascript' src='./Scripts/jquery.preloader.js'>";
}
Upvotes: 0