I have 1 HTML Page and 1 js file . I cannot run script in Firebug on Chrome
it shows following Error :
Access to restricted URI denied.
Code is as per tutorial
HTML Page
<!DOCTYPE html >
<html lang="en">
<head>
<meta charset="utf-8" />
<title>jQuery Example </title>
</head>
<body>
<input type="button" value="Hide" id="toggle_messege" />
<p id="messege">
You see this paragraph
</p>
<script type="text/javascript" src="~/js/toggle.js"></script>
<script type="text/javascript" src="~/js/jquery-1.7.1.min.js"></script>
</body>
</html>
js file
$('#toggle_messege').click(function () {
var value = $('#toggle_messege').attr('value');
$('messege').toggle('fast');
if (value == 'Hide') {
$('#toggle_messege').attr('value', 'Show');
}
else if (value == 'Show') {
$('#toggle_messege').attr('value', 'Hide');
}
});
Similar post :
Error: "Access to restricted URI denied"
http://jquery-howto.blogspot.in/2008/12/access-to-restricted-uri-denied-code.html
They suggest it is same domain policy issue and solution is to access file from webserver(localhost)
my url is
http://localhost/WebApplication2/js/
But couldnot solve the issue ..
plz suggest if something missing
You have errors in your code
1.Change the order of file , jquery reference is first
<script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="js/toggle.js"></script>
2.You code must be wrapped in $(document).ready() and it should be in <head> block
$(document).ready(function(){
$('#toggle_messege').click(function () {
var value = $('#toggle_messege').attr('value');
$('#messege').toggle('fast'); // You missed # in this line
if (value == 'Hide') {
$('#toggle_messege').attr('value', 'Show');
} else if (value == 'Show') {
$('#toggle_messege').attr('value', 'Hide');
}
});
});
DEMO
Related
<form>
<script src="https://cdn.razorpay.com/static/widget/subscription-button.js"
data-subscription_button_id="*********"
data-button_theme="rzp-dark-standard" async>
if (typeof response.razorpay_payment_id == 'undefined' ||
response.razorpay_payment_id < 1)
{
redirect_url = 'https://www.google.com/';
}
else
{
redirect_url = 'https://in.search.yahoo.com/?fr2=inr';
}
location.href = redirect_url;
</script>
</form>
This is the Razorpay subscription form.
This does not work to redirect.
Not sure, if this is the only problem you are facing, but if the <script> tag has the src attribute, browsers should ignore the content between <script> and </script>.
Try this example:
<!DOCTYPE html>
<html lang="en">
<head><meta charset="utf-8"><title>script example</title></head>
<body>
<script src="a.js">
console.log("inside");
</script>
</body>
</html>
while a.js contains:
console.log("from a.js");
This produces only from a.js output in the console. Removing the src attribute from <script> tag produces inside output in the console.
I am a noob for learning javascripts
Here I have a javascripts code
I made a button named "click"
when you click the button
it will send a value xx=1 to x
if the value is match with the condition
then it will print "Y", otherwise it will be "N"
but it always cannot shows the messagebox.
<html>
<head>
<title>test</title>
<script language="javascript">
function jclass(xx)
{
var x=xx;
if x==1
alert("Y");
else
alert("N");
}
</script>
</head>
<head>
<h1><a href="javascript:jclass(1);">click</h1>
</head>
</html>
I have also tried other ways like this.
but it still cannot work.
<html>
<head>
<title>test</title>
<script language="javascript">
function jclass()
{
var x=1;
if x==1
alert("Y");
else
alert("N");
}
</script>
</head>
<head>
<h1><a href="javascript:jclass();">click</h1>
</head>
</html>
You have syntax error in if condition. The basic if...else syntax requires condition inside parenthesis after if.
function jclass(xx){
var x=xx;
if (x==1)
alert("Y");
else
alert("N");
}
<h1><a href="javascript:jclass(1);">click</h1>
You must use the brackets
if(x == 1)
You are missing the brackets for comparison,its not python:)
You can check these type of errors in console and act upon exact statement
You should also put curly braces even for a single line in a block or condition to avoid any legacy or formatting issues when running code
Happy Programming
<html>
<head><title>test</title>
<script language="javascript">
function jclass(xx)
{
var x=xx;
if (x==1) {
alert("Y");
}
else {
alert("N");
}
}
</script>
</head>
<head>
<h1><a href="javascript:jclass(1);">click</h1>
</head>
</html>
This is the code:
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
function nameNotAva()
{
alert("Name already exists.");
//some code
}
function nameCheck()
{
var username = document.getElementById('uname').value;
var url = "http://rscript.org/lookup.php?type=namecheck&name=";
var curl = url + username;
$.ajax({
url : curl,
type : 'GET',
success : function(urlOutput){
if(urlOutput.contains('NAMECHECK: NOTAVALIBLE')){
nameNotAva();
}
}
});
}
</script>
</head>
<body>
<input class="textBox" id="uname" type="text" maxlength="15" required/>
<input type="button" onclick="nameCheck()" value="Submit">
</body>
</html>
The problem is there in the $.ajax part. I know this because when i put alert(curl); just before the ajax part, it displays the correct URL. If you want the complete info that what i am trying to do then goto- How to check output of a created URL?
I am using jquery library of the latest version.
You haven't included the jQuery library so $ is undefined and the script will error on the Ajax part.
In general, if you have a problem with some JavaScript: Open the JS console in your browser and pay attention to any error messages.
Update after comments suggest that the code in the question was incomplete:
This is the library i am using- <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js" type="text/javascript" />
Script elements are not defined as empty. The end tag is required.
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js">
</script>
http://jsfiddle.net/ksJEj/
Change the input type:
<input type="submit" value="Submit"/>
include this in your <head></head> tags:
HTML
<script type="text/javascript" src="ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
and this too:
HTML/JavaScript
<script type="text/javascript">
$(document).ready(function{
function nameNotAva() {
alert("Name already exists.");
//some code
}
$('input[type="submit"]').click(function (event) {
event.preventDefault();
var username = $('#uname').val();
$.get("http://rscript.org/lookup.php", {
'type': 'namecheck',
'name': username
}, function (urlOutput) {
if ($(urlOutput).contains('NAMECHECK: NOTAVALIBLE') == true) nameNotAva();
else alert("woohoo");
});
});
});
</script>
I'm using PhoneGap to develop an android app. in the index.html I load a js file like this:
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<link rel="stylesheet" href="styles/style.css" />
<link rel="stylesheet" href="styles/loading.css" />
<script src="scripts/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="scripts/cordova-2.5.0.js"></script>
<script type="text/javascript" src="scripts/readImages.js"></script>
<script type="text/javascript">
function onReadImage(event) {
//do something
}
document.addEventListener("onReadImage", onReadImage, false);
</script>
</head>
<body>
<!--
.....
-->
</body>
</html>
readImages.js
// Some codes
window.readImageEvent= document.createEvent("readImageEvent"); // line 4
readImageEvent.initEvent("onWeddingCakesRead", true, true);
//Some functions
readImageEvent.images = data;
document.dispatchEvent(readImageEvent);
but when I check LogCat, I see this error:
Uncaught Error: NOT_SUPPORTED_ERR: DOM Exception 9 at file:///android_asset/www/scripts/readImages.js: 4
Any ideas?
finally I found out the problem.
I changed the below code:
window.readImageEvent= document.createEvent("readImageEvent");
to:
window.readImageEvent= document.createEvent("Event");
Because "readImageEvent" is not a proper event type. This link could be so useful
about this issue.
According to developer.mozilla.org
The createEvent method is deprecated.
I guess, you can try something like this:
var readImageEvent = new CustomEvent(
"onReadImage",
{
detail: {
images: data
},
bubbles: true,
cancelable: true
}
);
document.dispatchEvent(readImageEvent);
More information about usage, compatibility, etc can be found HERE
I am following a JavaScript tutorial on the W3Schools website and I have the following code:
<html>
<head>
<title>Hello!</title>
</head>
<body>
<script type="text/javascript">
function confirmShow
{
var r = confirm("Press one...")
if (r == true)
{
alert("Button pressed == OK")
}
if (r == false)
{
alert("Button pressed == Cancel")
}
}
</script>
<input type="button" onclick="confirmShow()" value="Show Confirm Box" />
</body>
</html>
and whenever I preview it in Coda or in Safari the alert never shows up.
Thanks in advance!
"function confirmShow" => "function confirmShow()"
Firebug is good for js debugging, try it. Safari has options too, AFAIK.
function confirmShow
{
function confirmShow()
{
?
I don't know if this is your problem, but your button is outside the <body> tag. That might cause you some trouble...
Also one would usually put a script like this in the <head> element. Just FYI.
1) w3schools is filled with errors and omissions. Better tutorials can be found at howtocreate.co.uk
2) You have no DOCTYPE declaration, and you're using XHTML syntax.
2.1) IE doesn't support true, see webdevout.net/articles/beware-of-xhtml for more information
3) You need to encapsulate the within a element as well as another block-level element as per the specification
See below for a proper HTML5 document. Notice the location and syntax
<!DOCTYPE html>
<html>
<head>
<title>Hello!</title>
<script>
function confirmBox() {
var ret = confirm('Some Text');
/*
Note the 3 equal signs. This is a strict comparison operator, to check both the 'value' as well as the type. see https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Operators for more
*/
if(ret === true) {
alert('Alert box for "Okay" value');
}
else if(ret === false) {
alert('Alert box for "Cancel" value');
}
}
window.onload = function() {
// Execute the confirmBox function once the 'button' is pressed.
document.getElementById('confirmBox').onclick = confirmBox;
}
</script>
</head>
<body>
<form>
<p>
<input type="button" id='confirmBox' value="Show Confirm Box">
</p>
</form>
</body>
</html>