This is my html code given below:
<td> Delete</td>
It is showing following exceptions:
Multiple annotations found at this line:
- Invalid location of tag (td).
- Invalid location of text (+) in tag
(<a>).
- Invalid location of text (+"')") in
tag (<a>).
- Undefined attribute name (jobid).
Please help me to correct it.
This works fine for me, tested here
<!DOCTYPE html>
<html>
<script>
var jobid = 23;
function confirmGo(msg,url){
alert(msg);
alert(url);
}
</script>
<body>
<td> Delete</td>
</body>
</html>
Related
I'm getting HTML template response from API service, in that sometimes I'm getting link and its href value is empty string(but innerText has some value),
Can anyone help me how can I hide the anchor tag if only text is present and href is empty.
Sometimes HTML response provides multiple empty links, give solution to hide all the empty links.
<div class="hyper-btn">
User Profile
</div>
To hide anchor tag, by using CSS will hide the elements from document.
<!DOCTYPE html>
<html>
<style>
.hyper-btn a[href=""] {
display: none !important;
/* will hide all the empty anchor tags */
}
</style>
<body>
<div class="hyper-btn">
Empty Link
Link to some Address
</div>
</body>
</html>
To remove anchor tags from DOM itself, add below JavaScript
<!DOCTYPE html>
<html>
<body>
<div class="hyper-btn">
Empty Link
Link to some Address
</div>
<script>
const linkList = document.querySelectorAll('.hyper-btn a');
linkList.forEach(element => {
const targetURL = element.getAttribute('href');
if(!targetURL) {
element.remove(); // will be removed from DOM
}
});
</script>
</body>
</html>
I am not sure if this is possible or not...
I am trying to replace a specific part of a URL from my iframe with a string that is part of the mainframe's URL.
i.e. I am trying to replace the iframe link to include the userID.
Main URL: https://web.example.com?userID=9553c6
<iframe src="https://app.example.com?[Insert userID here]"></iframe>
If your site where is content under address https://web.example.com?userID=9553c6 in my opinion you can do this using eg. php
<body>
<iframe src="http://example.com?user_id=<?php echo urlencode($_GET['userId']) ?>"></iframe>
</body>
Then variable $_GET['userId'] will have value of 9553c6
Or you can use only js which will be a bit harder, because you have to parse location.search https://www.w3schools.com/jsref/prop_loc_search.asp and get specific part of it. Of course this value of param userId will be from main site.
Direct solution
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<style>
iframe {
width: 100%;
height: 1000px;
}
</style>
</head>
<body>
<iframe src="http://fotokrajobrazy.warmia.pl/galeria/fota.php?nr=1004"></iframe>
</body>
<script>
window.onload = function () {
var res = location.search.match(/userId\=(\w+)/);
var fr = document.getElementsByTagName('iframe')[0];
fr.setAttribute('src', fr.getAttribute('src').replace(/(nr\=)\d+/, '$1'+res[1]));
};
</script>
</html>
You can then edit main url like this:
http://127.0.0.1/stack.html?userId=1003
and
http://127.0.0.1/stack.html?userId=1002
etc. and the url of iframe will change too.
You need some simple string-hangling.
You say you're injecting the frame via JavaScript, so I'll suppose your code looks something like this.
let
ifr = document.createElement('iframe'),
src = 'some/url/here?user={user-id}',
user_id = '123456';
src = src.replace('{user-id}', user_id)
;
document.body.appendChild(ifr);
The key line is the one with .replace() - that's where we replace the placeholder with the actual value.
First off, let me beg forgiveness for being such a noob at web development. I have looked everywhere for how to do this and can't find anything that tells me specifically.
Here is my link:
<td><a style="color:red;text-align:left" href=/sponsor/manageuser.htm?user="
+ target=_self"</a></td>
I need the parameter "user" to be appended and I also need the exact same value as user as the link. Like this:
<td><a style="color:red;text-align:left"
href=/sponsor/manageuser.htm?user="12345" 12345</a></td>
The problem is that I have to put the param and the link inside the tag. At least I think that's the problem So you click on 12345 link, it appends 12345 to the URL and passes it as a GET method. My form is a GET:
<form class="frm" method="get" name="currentusers" id="currentusers"
action="currentusers.htm">
And then here's what my URL looks like and of course I get a 404 error:
http://localhost:8080/sponsor/manageuser.htm?user=target=
Any advice is appreciated in advance.
jQuery way:
What you can do is have each link call a function and pass the value of the link into the function. The function append() will then add a hidden input value with the number you clicked on. Finally, the function will submit the form to the manageuser.htm page with the "?user=1234" as you requested.
You can see how the code works by copying and pasting this code and opening it on your computer.
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<form id = "form1" method="get" action="sponsor/manageuser.htm">
<table>
<tr>
<td><button id="1543" onclick="append(1543)">1543</button></td>
<td><button id="3515" onclick="append(3515)">3515</button></td>
<td><button id="1115" onclick="append(1115)">1115</button></td>
</tr>
</table>
</form>
<script>
function append(user_number)
{
$('<input />').attr('type', 'hidden').attr('name', "user").attr('value', user_number).appendTo('#form1');
$('#form1').submit();
}
</script>
</body>
</html>
I am not getting the expected message when using value recipe.
I am getting output as {{message}}, but I am expecting "hai services are working!!"
Please share where I am going wrong.
HTML code: Injector.html
<!DOCTYPE html>
<html>
<head>
<title>Practicing Angular JS</title>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular.min.js"></script>
<script src="Injector.js"></script> <!-- Injector module file name -->
</head>
<body ng-app="injectormodule"> <!-- root module-->
<div ng-controller="controllerInjector">
{{message}}
<!-- controller name-->
</div>
</body>
</html>
Controller: Injector.js
var app = angular.module("injectormodule", ["servicemodule"])//name of service is servicemodule
.controller("controllerInjector", ["$scope", "message", function($scope, message){
$scope.message = message;
}]);
Service:(Value Recipe)
var myapp = angular.module("servicemodule", [])
.value("message", "hai services are working!!");
You have to define your servicemodule before your injectormodule, otherwise its creation will fail (since unable to find the servicemodule dependence).
Since the injectormodule failed from being created, the ng-app="injectormodule" will also be unable to bootstrap Angular on your DOM, thus won't interpret things like double brackets ({{ message }}).
Here is a working codepen.
You need to Inject your service into controller and need to create same module.
See this sample working fiddle which use service method to get text.
See other fiddle link also in comments
e.g. I have a file named: /SW1A2AA.htm
In the HTML I need to show the following image with the source for the image to include the filename (without the extension). I.e.:
<img src= "https://maps.googleapis.com/maps/api/staticmap?center=sw1a2aa&zoom=18&size=640x480">
Obviously if I need to do this for lots of pages, it would be easier if there was a way to amend the search string to depend on the filename (without the extension).
Please tell me there is a simple way to produce that result!
Thanks
Here is my solution for your example (SW1A2AA.htm). Empty src attribute is not valid, so we use //:00 - you can read more about this solution here.
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Page Title</title>
</head>
<body>
<img id="map" src="//:0">
<script>
// grab the URL. I'm working locally so in my case it is /C:/Users/myLogin/Desktop/SW1A2AA.htm
var pageURL = window.location.pathname;
// find the last position of the "/"
var fileNamePosition = pageURL.lastIndexOf("/");
// take file name and delete last 4 characters (SW1A2AA.htm -> SW1A2AA)
var fileName = pageURL.slice(fileNamePosition+1,-4);
// create src
var mapSrc = "https://maps.googleapis.com/maps/api/staticmap?center=" + fileName + "&zoom=18&size=640x480";
// update map src attribute
var map = document.getElementById("map");
map.setAttribute("src", mapSrc);
</script>
</body>
</html>