Google Map API inside a xhtml jsf page [duplicate] - javascript

I have Google checkout sandbox generated HTML code which works fine in HTML page. When I put the same code in XHTML page, it throws the below exception:
the reference to entity "w" must end with the ';' delimiter
It's referring the request parameter w in the URL in the below src attribute:
<input type="image" name="Google Checkout" alt="Fast checkout through Google"
src="http://sandbox.google.com/checkout/buttons/checkout.gif?merchant_id=211512493599623&w=180&h=46&style=white&variant=text&loc=en_US"
height="46" width="180" />
How is this caused and how can I solve it?

The ampersand & is a special character in HTML and XML. If you want to use it as a normal character, you have to encode it correctly. Write & instead of &:
src="...9623&w=180&h=46&style=white&variant=text&loc=en_US"
& denotes the start of an encoded entity, such as < for <, or & for &. In your case the parser tries to interpret &w as an entity. But entities are always terminated by an ;, thus if the ; is missing you get the error message.

This worked on my side, when using search iq's installation code on my Blogger blog's HTML file:
<script type="text/javascript">
(function () {
window.siqConfig = {
engineKey: "6e14b3aacb2b93b658f8729adec0c030",
forceLoadSettings: false // change false to true if search box on your site is adding dynamically
};
window.siqConfig.baseUrl = "//pub.searchiq.co/";
var script = document.createElement("SCRIPT");
script.src = window.siqConfig.baseUrl + '/js/container/siq-container-2.js?cb=' + (Math.floor(Math.random()*999999)) + '&engineKey=' + siqConfig.engineKey;
script.id = "siq-container";
document.getElementsByTagName("HEAD")[0].appendChild(script);
})();
Gave me error here: &engineKey, after adding &amp replacing the & I was able to save my HTML file.

Related

Javascript - Forward Slash appended automatically in URL with the Window.Location.Hash

In my Angular JS website, I wish to append the text "#Page/" to the URL using Javascript. Here my problem is that the forward slash(/) is getting added when using the code Location.hash
For example, Let say the URL is https://MyWebsite.com/Products
var location = window.location;
location.hash = "#page/" + pageNumber;
window.location = location
After executing the above code, the Window.location turned out to be https://MyWebsite.com/Products/#page/1.
But what I need is the forward slash(/) should not be included between products and #page.
https://MyWebsite.com/Products#page/1.
The strange thing is that when I checked the same code with the other websites don't have Angular JS, implemented only with the Asp.net Webforms and ASP.net MVC, I got the desired result.
Does this kind of issue have something to do with the Angular JS?
I believe # is special character reserved for a page fragment reference.
See https://www.ietf.org/rfc/rfc3986.txt
Can you do with without # or use the # to reference the fragment? e.g.
window.location.href += 'page/' + pageNumber + '#' + pageFragment;

Can not push HTML block into the android html page

I am getting a HTML block from server and want to push it into a html page in android application.
A sample html coming from server (this is the exact output with crlf etc. printed in logcat):
<ul>
<li>217</li>
<li>214</li>
</ul>
This is how I pass the output to the application html page:
runJavaScript("setHTML('"+ html +"')");
public void runJavaScript(final String code){
webview.post(new Runnable() {
#Override
public void run() {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
webview.evaluateJavascript(code, null);
}else {
webview.loadUrl("javascript:" + code);
}
}
});
}
and this is the Javascript setHTML function inside the html page which is being called from android:
function setHTML(html){
$("#result").html(html);
}
this is the error:
"Uncaught SyntaxError: Invalid or unexpected token", source:
file:///android_asset/html/en/result.html (1)
I have tried debugging the project by replacing the HTML block with a simple word and it works. I think HTML characters like quotation or crlf may produce the error but I don't want to escape them (I dont want to set pure text but real html). How should I change current codes? thanks.
I guess, it's too late and doesn't answer your question exactly, as you don't want to escape any characters (I'm not sure why though), but maybe it will help somebody.
In my case, before running
runJavaScript("setHTML('"+ html +"')");
I had to escape all single quotation marks and it was enough.
html = html.replace("'", "\\'");

How to solve error while parsing HTML

I´m trying to get the elements from a web page in Google spreadsheet using:
function pegarAsCoisas() {
var html = UrlFetchApp.fetch("http://www.saosilvestre.com.br").getContentText();
var elements = XmlService.parse(html);
}
However I keep geting the error:
Error on line 2: Attribute name "itemscope" associated with an element type "html" must be followed by the ' = ' character. (line 4, file "")
How do I solve this? I want to get the H1 text from this site, but for other sites I´ll have to select other elements.
I know the method XmlService.parse(html) works for other sites, like Wikipedia. As you can see here.
The html isn't xml. And you don't need to try to parse it. You need to use string methods:
function pegarAsCoisas() {
var urlFetchReturn = UrlFetchApp.fetch("http://www.saosilvestre.com.br");
var html = urlFetchReturn.getContentText();
Logger.log('html.length: ' + html.length);
var index_OfH1 = html.indexOf('<h1');
var endingH1 = html.indexOf('</h1>');
Logger.log('index_OfH1: ' + index_OfH1);
Logger.log('endingH1: ' + endingH1);
var h1Content = html.slice(index_OfH1, endingH1);
var h1Content = h1Content.slice(h1Content.indexOf(">")+1);
Logger.log('h1Content: ' + h1Content);
};
The XMLService service works only with 100% correct XML content. It's not error tolerant. Google apps script used to have a tolerant service called XML service but it was deprecated. However, it still works and you can use that instead as explained here: GAS-XML
Technically HTML and XHTML are not the same. See What are the main differences between XHTML and HTML?
Regarding the OP code, the following works just fine
function pegarAsCoisas() {
var html = UrlFetchApp
.fetch('http://www.saosilvestre.com.br')
.getContentText();
Logger.log(html);
}
As was said on previous answers, other methods should be used instead of using the XmlService directly on the object returned by UrlFetchApp. You could try first to convert the web page source code from HTML to XHTML in order to be able to use the Xml Service Service (XmlService), use the Xml Service as it could work directly with HTML pages, or to handle the web page source code directly as a text file.
Related questions:
How to parse an HTML string in Google Apps Script without using XmlService?
What is the best way to parse html in google apps script
Try replace itemscope by itemscope = '':
function pegarAsCoisas() {
var html = UrlFetchApp.fetch("http://www.saosilvestre.com.br").getContentText();
html = replace("itemscope", "itemscope = ''");
var elements = XmlService.parse(html);
}
For more information, look here.

Rails 4 - Layouts only showing half the time with javascript

I made a little script in javascript to display a different image based on the day, it works fine but half the time when I load the page only the image will be displayed and not the rest of the app(no menus) and the other half everything is working perfectly.
I put the JS code in the index.html.erb file since it's really small, should I put it somewhere else or the problem is elsewhere?
EDIT :
I ended up writing it in coffeescript in the .js.coffee file with an "#" in front of the name of the function and tell call it in the view and I still got the same problem.
View file (app/view/module/index.html.erb)
<script type="text/javascript">
#myfunction();
</script>
function : in app/assets/javascripts/module.js.coffee
#day = ->
today = new Date
number = today.getDay() + 1
document.write '<img src="url' + number +'.jpg">'
return
document.write will erase everything in the html before writing to it, that's why you only see the image.
You should do something like this instead:
placeholder = document.getElementById("placeholder")
placeholder.innerHTML = '<img src="url' + number +'.jpg">'
where placeholder is an existing element in the html with id of "placeholder"
You can't use coffescript in a script tag* - sprockets will not convert the coffee script to javascript which the browser can actually run.
If you had checked the browser console you would have seen that # causes a syntax error in javascript.
SyntaxError: Unexpected token ILLEGAL
When javascript hits a syntax error it will stop executing the script.

Javascript to open a file on a shared drive is not working

Gang,
I'm hoping someone can tell me what I'm doing wrong here. I've searched several places and everything I'm doing should be working, but it's not. I have a page on a local company intranet. When someone clicks a checkbox for a category with a related document, the page should open up a file (usually a .docx or .xlsx) from the network shared drive. I put in an alert message to make sure it was passing through that part of the function. That works, but nothing happens after that. Here's the function and here's how I'm calling it.
<script type="text/javascript">
function opensupport(chkbox, url) {
var x = document.getElementById(chkbox)
if (x.checked) {
if (confirm(x.value + " has an associated document to complete. Would you like to open that now?")) {
alert("opening " + url);
window.open(url, 'newwin');
}
}
}
Here's how I'm calling it...
<input type='checkbox' name='initiative' id='34' value='Test Link' onclick="opensupport('34', 'file:\\qdcns0001\projects\EAI Vendor Management\fact sheets\docs\AdvancedMD_Fact_Sheet.doc')"/>
In a Javascript string literal the backslash is the escape character. You need to use double backslashes to get a backslash in a string:
'file:\\\\qdcns0001\\projects\\EAI Vendor Management\\fact sheets\\docs\\AdvancedMD_Fact_Sheet.doc'
As user 11684 pointed out, an URL normally uses slashes, not backslashes, so that wold be:
'file://qdcns0001/projects/EAI Vendor Management/fact sheets/docs/AdvancedMD_Fact_Sheet.doc'
Also, you may need to URL encode the spaces in the URL. Although most browsers are very lenient about this, an URL according to the standards may not contain spaces.
'file://qdcns0001/projects/EAI%20Vendor%20Management/fact%20sheets/docs/AdvancedMD_Fact_Sheet.doc'
You need to escape the slashes
file://///qdcns0001\projects\EAI Vendor Management\fact sheets\docs\AdvancedMD_Fact_Sheet.doc

Categories

Resources