visual studio pops up a notification saying "Microsoft JScript runtime error: 'initMap' is undefined" and points to the line below that contains "initMap();".
Notice, i've included a reference to the javascript file i'm using in the aspx page.
Error at: (this is from Default.aspx [dynamic] when debugging)
<script type="text/javascript">
//<![CDATA[
initMap();Sys.Application.add_init(function() {
$create(Sys.UI._Timer, {"enabled":true,"interval":4000,"uniqueID":"Timer1"}, null, null, $get("Timer1"));
});
//]]>
<
Default.aspx.cs:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (!ClientScript.IsStartupScriptRegistered("init"))
{
Page.ClientScript.RegisterStartupScript
(this.GetType(), "init", "initMap();", true);
//"<body onload="initialize()"> "
//"initialize();"
}
}
}
Default.aspx:
<%# Page Title="Home Page" Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs"
Inherits="MyProject._Default" %>
<!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">
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
......[some stuff here]
</style>
<title>Home Page</title>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true®ion=PK"></script>
<script type="text/javascript" src="defaultPage.js"></script>
</head>
<body>
<form id="form1" name="form1" runat="server">
..... [some stuff here]
</form>
</body>
</html>
My defaultPage.js file contains the following:
var geocoder;
var map;
var initialLocation = new google.maps.LatLng(24.828417, 67.038445);
var browserSupportFlag = new Boolean();
var markersArray = [];
images = new Object();
images.length = 99;
function initMap() {
....[some code here]
}
....
[more functions here]
Related
I'm trying to create a click event in Vue in a static HTML file as test but it doesn't work as expected. See full code below:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--[if IE]><![endif]-->
<!--Empty IE conditional comment to improve site performance-->
<html lang="en">
<head>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
</head>
<body>
<script type="text/babel">
var titleFilter = new Vue({
el: '#filter',
methods: {
clickEvent: function(){
console.log('Vue is working.');
}
}
});
</script>
<a id="filter" v-on:click="clickEvent" href="#">CLICK ME</a>
</body>
</html>
So as a checklist:
I have my function in a method object
Function names are correct
I'm including the library
In my script tag, I'm specifing babel as type
It's not working, what's wrong?
This works
<html lang="en">
<head>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
</head>
<body>
<a id="filter" v-on:click="clickEvent" href="#">CLICK ME</a>
<script type="text/javascript">
var titleFilter = new Vue({
el: '#filter',
methods: {
clickEvent: function(){
console.log('Vue is working.');
}
}
});
</script>
</body>
</html>
Change text/babel to text/javascript and move your JS code below
I have 3 index pages say
index_ch.jsp
,index_ie.jsp
,index_me.jsp
and a main parent page named
browserdetect.jsp
when the user first enters my url in a browsere browserdetect.jsp will run ...... what i need is the jquery or java script that can be put in my browserdetect.jsp which will first detect the browser the user uses and then redirect to the respective index pages based on the browser he or she uses ...... can any one help me out please
Adding this script to my head section helped me to do what i wanted .... thank you for the help guys ........
if ((navigator.userAgent.indexOf('MSIE') >= 0) && (navigator.userAgent.indexOf('Opera') < 0))
{
window.location.replace("your page");
}
else if (navigator.userAgent.indexOf('Chrome') >= 0)
{
window.location.replace("your page");
}
else
{
window.location.replace("your page");
}
</script>
This code helps you to detect browser of user.
var x = "User-agent header sent: " + navigator.userAgent;
I guess you want to detect brower of user
if ((navigator.userAgent.indexOf('MSIE') >= 0) && (navigator.userAgent.indexOf('Opera') < 0))
{
the code of index_ie.jsp...
}
else if (navigator.userAgent.indexOf('Chrome') >= 0)
{
the code of index_ch.jsp...
}
else
{
the code of index_me.jsp...
}
browserdetect.jsp ------page
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript">
function detectBrowser(){
var nAgent = navigator.userAgent;
var verOffset;
if ((nAgent.indexOf("MSIE"))!=-1) {
browserName = "Microsoft Internet Explorer";
window.location = "index_ie.jsp";
}
else if ((verOffset=nAgent.indexOf("Chrome"))!=-1) {
browserName = "Chrome";
window.location = "index_ch.jsp";
}
else if ((verOffset=nAgent.indexOf("Firefox"))!=-1) {
browserName = "Firefox";
window.location = "index_me.jsp";
}
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body onload="detectBrowser()">
<h1>Hello World!</h1>
</body>
</html>
===============================================================================
index_ch.jsp -----page
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Hello World! Chrome</h1>
</body>
</html>
=========================================================================
index_ie.jsp -----page
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Hello World! Internet Explorer</h1>
</body>
</html>
=============================================================================
index_me.jsp -----page
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Hello World! Mozilla Firefox</h1>
</body>
</html>
you can use jsp redirecting tags
1. jsp:forward :- server side redirect [not show index_ie.jsp in the URL]
2. response.sendRedirect :-browser side redirect[ show index_ie.jsp in the URL]
instead of window .location.
I want the button on the second page to change the value of the button in the first page,this is my code:
FILE 1: Index.html(page one):
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Eran Exercise</title>
<link rel="stylesheet" type="text/css" href="design.css" />
<script src="new_file.js"></script>
</head>
<body>
<div class="wrapper">
<form>
<input type="button" id="id200" value="New Window!" onClick="window.open('page2.html','mywindow','width=400,height=200')">
</form>
</div>
</body>
</html>
FILE 2:new_file.js(the js file)
function changeLink()
{
var someOtherName="after click";
xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("id200").value = someOtherName;
}
}
xmlhttp.open("GET","index.php");
xmlhttp.send();
}
FILE 3:page2.html (page two)
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<script src="new_file.js"></script>
</head>
<body>
<input type="button" id="id100" onclick="changeLink()" value="Change link">
</body>
</html>
Thanks!
Replace
document.getElementById("id200").value = someOtherName;
by
window.opener.document.getElementById("id200").value = someOtherName;
previous answer +1
but it will work only on the same domain or if the server sends special header
you can use cookies or local storage
save in it state on the second page and get it on the first page
also you can use php script and get/save the state from/to there
you had missed the third parameter at xhr.open
and never use sincronious requests
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
Hello first time i used jqgrid but data not loaded in UI
*html file:*
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>My First Grid</title>
<link rel="stylesheet" type="text/css" media="screen" href="css/ui-redmond/jquery-ui-1.8.12.custom.css" />
<link rel="stylesheet" type="text/css" media="screen" href="css/ui.jqgrid.css" />
<style>
html, body {
margin: 0;
padding: 0;
font-size: 75%;
}
</style>
<script src="js/jquery-1.5.2.min.js" type="text/javascript"></script>
<script src="js/i18n/grid.locale-en.js" type="text/javascript"></script>
<script src="js/jquery.jqGrid.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
$("#list").jqGrid({
url:'/home/vbalamurugan/sename.jsp',
datatype: 'xml',
mtype: 'GET',
colNames:['PROPERTY_NAME','PROPERTY_VALUE'],
colModel :[
{name:'PROPERTY_NAME', index:'PROPERTY_NAME', width:300},
{name:'PROPERTY_VALUE', index:'PROPERTY_VALUE', width:300},
],
pager: '#pager',
rowNum:5,
rowList:[10,20,30],
sortname: '',
sortorder: 'desc',
viewrecords: true,
caption: 'Bala First Grid'
});
});
</script>
</head>
<body>
<table id="list"></table>
<div id="pager"></div></body>
</html
jsp
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%# page import="java.sql.*" %>
<%# page import="java.io.*" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
String jdbcURL = "jdbc:oracle:thin:#192.168.6.38:1521:XE";
Connection conn = null;
Statement stmt = null;
ResultSet rs =null;
String user ="raymedi_hq" ;
String passwd ="raymedi_hq";
int count=8;
StringBuffer sbf=new StringBuffer(250);
try {
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
conn = DriverManager.getConnection(jdbcURL,user,passwd);
stmt = conn.createStatement();
response.setContentType("text/xml;charset=utf-8");
response.setHeader("", "Content-type: text/xml;charset=utf-8");
sbf.append("<?xml version='1.0' encoding='utf-8'?>");
sbf.append("<page>2</page>");
sbf.append("<total>3</total>");
sbf.append("<records>"+count+"</records>");
rs = stmt.executeQuery("SELECT PROPERTY_NAME,PROPERTY_VALUE FROM HQ_FA_TAG");
while(rs.next())
{
sbf.append("<cell><![CDATA["+rs.getString("PROPERTY_NAME")+"]]></cell>");
sbf.append("<cell><![CDATA["+rs.getString("PROPERTY_VALUE")+"]]></cell>");
}
sbf.append( "</row>");
sbf.append("</rows>");
out.println(sbf.toString);
System.out.println(sbf.toString());
rs.close();rs=null;
if (conn != null){
try{
conn.close();
}catch(Exception ex2){ex2.printStackTrace();}
}
}
catch(Exception e){e.printStackTrace();}
%>
</body>
</html>
How you can see here the XML data which you posted can be read by jqGrid. I inserted only two blanks in the first line. I hope it was cut&paste errores.
Moreover I inserted type="text/css" attribzte to the <style> element and <tr><td/></tr> inside of <table> element. After the changes the validator.w3.org find no problems more. I inserted additionally height:'auto'. The parameters datatype: 'xml' and mtype: 'GET' can be also removed, because the values are default (see the documentation).
I am new to JavaScript and here is a problem when I trying out prototype.
I want to update sample.jsp with Ajax.updater after the it is loaded, but it doesn't work. Here the source of smaple.jsp.
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>JSP Page</title>
<script src="prototype.js"></script>
<script>
function f1(){
var ajax = new Ajax.updater(
{success: 'state'},'part.html'
,{method:'get'});
}
document.observe('dom:loaded', function() {
f1();
});
</script>
</head>
<body>
state:
<div id="state"></div>
<br>
</body>
</html>
Could anyone tell me what's wrong with my code?
try "Ajax.Updater" (capital U) for starters
also I recommend that you try working with firefox and the firebug plugin, it's a great way to debug your javascript
I have tried another one and it works
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>AJAX Zip Checker </title>
<link rel="stylesheet" href="style.css" type="text/css" />
<script src="prototype.js"></script>
<script type="text/javascript" language="JavaScript">
function checkZip() {
if($F('zip').length == 5) {
var url = 'checkzip.jsp';
var params = 'zip=' + $F('zip');
var ajax = new Ajax.Updater(
{success: 'zipResult'},
url,
{method: 'get', parameters: params, onFailure: reportError});
}
}
function reportError(request) {
$F('zipResult') = "Error";
}
</script>
</head>
<body>
<label for="zip">zip:</label>
<input type="text" name="zip" id="zip" onkeyup="checkZip();" />
<div id="zipResult"></div><p/>
</body>
</html>
checkzip.jsp
<%
String zip = request.getParameter("zip");
if (zip.equals("10009")) {
%>
new york
<%} else {%>
unknown
<% }%>
Could anyone tell me the difference?