I am trying to call firebreath functions from my javascript file.Everything works fine if I call the firebreath functions using an html document with javascript functions and also for firefox version upto 28. For higher versions of firefox on calling the functions through plugin I get an error "TypeError:plugin.echo is not a function" (echo is an inbuilt firebreath function). Find the below code for reference.
overlay.xul
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/"?>
<overlay id="mypluginOverlay" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml">
<script type="application/x-javascript" src="chrome://myplugin/content/ngContent.js"/>
<vbox style="height:0;">
<html:object type="application/x-myplugin" id="myplugin" style="height:0;"></html:object>
</vbox>
</overlay>
ngContent.js
try
{
var plugin = document.getElementById('myplugin');
alert(plugin); // Output for firefox version upto 28 : <JSAPI-Auto Javascript Object>
//Output for firefox higher versions : [object HTMLObjectElement]
plugin.echo("qwerty");
}
catch(ErrorMessage)
{
alert(ErrorMessage);
}
Can anyone help me in this??? Thanks in advance....
EDIT:
Tried html:embed tag instead of html:object in overlay.xul.
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/"?>
<overlay id="mypluginOverlay" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml">
<script type="application/x-javascript" src="chrome://myplugin/content/ngContent.js"/>
<vbox style="height:0;">
<html:embed type="application/x-myplugin" id="myplugin" style="height:0;"></html:embed>
</vbox>
</overlay>
It doesn't work either.
Related
For some browsers, for some clients, jquery suddenly stopped parsing xml.
Example xml:
<?xml version="1.0" encoding="UTF-8"?>
<wfs:FeatureCollection xmlns:wfs="http://www.opengis.net/wfs" xmlns="http://www.opengis.net/wfs" xmlns:gml="http://www.opengis.net/gml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:example_namespace="https://mylink.com/wfs/example_namespace" xsi:schemaLocation="https://mylink.com/wfs/example_namespace mylink.com?SERVICE=WFS&VERSION=1.0.0&TYPENAME=example_namespace:TABLE&REQUEST=DescribeFeatureType" numberMatched="unknown" numberReturned="1">
<gml:featureMember>
<example_namespace:TABLE fid="TABLE.15">
<example_namespace:ID>15</example_namespace:ID>
</example_namespace:TABLE>
</gml:featureMember>
</wfs:FeatureCollection>
Example jquery
$.get(link, function(data) { //Response is xml like in example.
console.log(data) //works as before
console.log($(data).find("featureMember").find("ID").text())
//Doesn't work now for some clients, but worked before.
})
EDIT:
More general example:
XML
<?xml version="1.0" encoding="UTF-8"?>
<a xmlns:c="http://www.example.com">
<c:b>TEST</c:b>
</a>
AND JS:
console.log($(data).find("b").text())
now returns: "", before returns: "TEST"
EDIT 2:
Similar problem:
Cannot extract SOAP XML with jQuery
This code was originally working in Chrome last week and once Chrome
updated to v60 it no longer does.
Pass data to $.parseXML() to get a #document, use .querySelector()
$.parseXML(data).querySelector("featureMember").querySelector("ID").textContent;
alternatively pass result of $.parseXML() to jQuery() and use .find()
$($.parseXML(data)).find("featureMember").find("ID").text();
jsfiddle https://jsfiddle.net/5fuLquth/
Parsing XML using jQuery in this way has some browser compatibility bugs I believe. This has been a won't fix jquery bug previously.
When there are namespaces in the xml you can use jquery selectors like the below by escaping the colon:
.find('gml\\:featureMember')
or using nodeName:
.find('[nodeName="gml:featureMember"]')
See demo below:
var xml=`<?xml version="1.0" encoding="UTF-8"?><wfs:FeatureCollection xmlns:wfs="http://www.opengis.net/wfs" xmlns="http://www.opengis.net/wfs" xmlns:gml="http://www.opengis.net/gml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:example_namespace="https://mylink.com/wfs/example_namespace" xsi:schemaLocation="https://mylink.com/wfs/example_namespace mylink.com?SERVICE=WFS&VERSION=1.0.0&TYPENAME=example_namespace:TABLE&REQUEST=DescribeFeatureType" numberMatched="unknown" numberReturned="1"><gml:featureMember><example_namespace:TABLE fid="TABLE.15"><example_namespace:ID>15</example_namespace:ID></example_namespace:TABLE></gml:featureMember></wfs:FeatureCollection>`;
console.log($(xml)
.find('gml\\:featureMember')
.find("example_namespace\\:ID").text());
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
I'm trying to dynamically create an image which I will then append to the DOM.
import org.w3c.dom.HTMLImageElement
fun main(args: Array<String>) {
// load footer banner image
val img: HTMLImageElement = HTMLImageElement()
with (img){
src = "img/footer.png"
classList.add("img-responsive")
}
}
However, it doesn't like my constructor HTMLImageElement() since HTMLImageElement is an interface.
Removing the constructor and Kotlin complains that img must be initialised.
What is the correct way to make use of the HTMLImageElement in a type-safe way ?
Update: I'm now using maven which generates everything as it should.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.blah</groupId>
<artifactId>blah</artifactId>
<packaging>jar</packaging>
<version>1.0.0</version>
<name>Blah</name>
<properties>
<kotlin.version>1.0.2</kotlin.version>
<kotlin.html.version>0.5.8</kotlin.html.version>
</properties>
<repositories>
<repository>
<id>bintray-kotlinx</id>
<name>bintray</name>
<url>http://dl.bintray.com/kotlinx/kotlinx</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx.html.js</artifactId>
<version>${kotlin.html.version}</version>
</dependency>
</dependencies>
</project>
which compiles a blah.js, blah.js.map, blah.js.meta, kotlin.js, kotlinx.html.js, kotlinx.html.meta.js, kotlinx.html.shared.js, kotlinx.html.shared.meta.js and stdlib.meta.js.
In my html file (which is sitting in my root directory) I'm including the following:
<script type="text/javascript" src="js/jquery-1.12.4.js"></script>
<script type="text/javascript" src="js/bootstrap.js"></script>
<script type="text/javascript" src="target/classes/kotlin.js"></script>
<script type="text/javascript" src="target/classes/kotlinx.html.shared.js"></script>
<script type="text/javascript" src="target/classes/blah.js"></script>
I've got a println("hello world") in my Main.kt which executes fine in the browser printing "hello world" in the browswer console.
Now I still want to append that image dynamically using Kotlin ...
The docs say I should be doing document.create.div("panel") to create a div, but document.create... autocompletes to createAttribute, createComment etc, no create() method in sight anywhere. (document is from package 'kotlin.browser').
I'm not exactly sure how to use kotlinx.html since what I'm seeing in IntelliJ doesn't match the docs.
How do I append a dynamically created image to an existing div using KotlinJS ?
I just write sample project with kotlin2js and kotlinx.html IRus/kotlin-kotlinx.html. Looks like current version of kotlinx.html (0.5.8) not compatible with Kotlin 1.0.2, but works well with kotlin 1.0.1-2.
I have started a new project - javascript - windows universal app and without changing anything or adding any code I try to build it and run it but it wont with the following error:
Error : DEP0700 : Registration of the app failed. error 0x80080204: App manifest validation error: The document root element m:Package must be defined in the http://schemas.microsoft.com/appx/2010/manifest namespace. (0x80080204) App7
A similar issue was reported here and I tried renewing the license with project -> store -> aquire developer license to no avail. It seems to be that the actual problem has to be the document root element part which I'm not really familiar with as I haven't worked with Visual Studio before I tried to add xmlns:m="http://schemas.microsoft.com/appx/2010/manifest" to my package appxmanifest but that doesn't seem to have helped.
Heres the whole manifest:
<?xml version="1.0" encoding="utf-8"?>
<Package
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
xmlns:m="http://schemas.microsoft.com/appx/2010/manifest"
IgnorableNamespaces="uap mp m">
<Identity
Name="155dc546-80c7-4275-b2a6-a2aa8ddec5f7"
Version="1.0.0.0"
Publisher="CN=FroboZ" />
<mp:PhoneIdentity PhoneProductId="155dc546-80c7-4275-b2a6-a2aa8ddec5f7" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>
<Properties>
<DisplayName>App7</DisplayName>
<PublisherDisplayName>FroboZ</PublisherDisplayName>
<Logo>images\storelogo.png</Logo>
</Properties>
<Dependencies>
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.10069.0" MaxVersionTested="10.0.10069.0" />
</Dependencies>
<Resources>
<Resource Language="x-generate" />
</Resources>
<Applications>
<Application
Id="App"
StartPage="default.html">
<uap:VisualElements
DisplayName="App7"
Description="App7"
BackgroundColor="#464646"
Square150x150Logo="images\Logo.png"
Square44x44Logo="images\SmallLogo.png">
<uap:SplashScreen Image="images\splashscreen.png" />
</uap:VisualElements>
</Application>
</Applications>
<Capabilities>
<Capability Name="internetClient" />
</Capabilities>
</Package>
Thank you for taking your time to read my question and even more so if you can help me with this problem!
Developer mode wasn't turned on in windows 10. I'm not sure what difference this makes but after turning this on I was able to build the project.
I am having issues using the <script> tag in Ant and I am hoping someone can help. I want to use JavaScript in my Ant build.xml. Something like the following:
<?xml version="1.0" encoding="UTF-8"?>
<project name="java" default="main" basedir=".">
<target name="main">
<script language="javascript"> <![CDATA[
println("hello, world")
]]> </script>
</target>
</project>*
Unfortunately this only displays and error:
build.xml:4: Could not create task or type of type: script.
I have located the required jar file (js.jar) for this to work and moved it to ANT_HOME/lib, but I am still stuck as of how to get this to work.
In addition to js.jar, you need to add bsf.jar and commons-logging-*.jar to ANT_HOME/lib. In your Ant distribution, there is a file named docs/manual/install.html. The Library Dependencies section of this HTML file documents where you can download these files.
println isn't supported in JavaScript. Instead, use the following:
<project name="jsTest" default="main">
<target name="main">
<script language="javascript"> <![CDATA[
var echo = jsTest.createTask("echo");
echo.setMessage("hello, world");
echo.perform();
]]> </script>
</target>
</project>
You can also instantiate and use Java classes in Javascript as available via Rhino(JRE pre 1.8) or Nashorn(JRE 1.8+) when you need to.
<script language="javascript">
with(new JavaImporter(java.lang, java.io)){
System.out.println("hello, world");// <--!!!
}
</script>
You may create and use JavaScript functions of your own.
<script language="javascript">
with(new JavaImporter(java.lang, java.io)){
var fun = function(a,b){
System.out.println(a+b);
};
fun(1,2);
}
</script>
Code above prints
3.0
Loops, recursion and everything you've been dreaming about... except strong type checking:-)
Beside the two syntax errors - missing ';' after println.. and trailing '*' after closing project tag - you should upgrade your ant installation to a version >= 1.7.x in conjunction with jdk >= 6 to be able to use the builtin javascript engine.
When using jdk >=6 the use of println is no problem, see :
import javax.script.*;
public class ExecuteJS {
public static void main(String[] args) throws Exception {
ScriptEngineManager factory = new ScriptEngineManager();
ScriptEngine engine = factory.getEngineByName("JavaScript");
engine.eval("print('Line1')");
engine.eval("println('Line2')");
engine.eval("print('Line3')");
engine.eval("println('Line4')");
}
}
output :
Line1Line2
Line3Line4
and
<project>
<script language="javascript">
println("hello, world");
</script>
</project>
But further testing with Ant 1.9.0 / Win7 (my linux box is down right now) / jdk1.7.0_21 revealed some oddities :
<project>
<script language="javascript">
println("hello, world");
</script>
</project>
works
<project default="foo">
<target name="foo">
<script language="javascript">
println("hello, world");
</script>
</target>
</project>
works also
<project name="whatever" default="foo">
<target name="foo">
<script language="javascript">
println("hello, world");
</script>
</target>
</project>
works also, whereas
<project name="java" default="foo">
<target name="foo">
<script language="javascript">
println("hello, world");
</script>
</target>
</project>
results in
BUILD FAILED
javax.script.ScriptException: sun.org.mozilla.javascript.internal.EcmaError: TypeError: Cannot read property "PrintWriter" from undefined (print#8) in print at line number 8
Strange !? Seems like a bug, so finally upgrade ant >= 1.7.x and jdk >= 1.6 and don't use 'java' in name attribute of project :-)
I have a script that I add to my xul file, like:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Bindings -->
<?xml-stylesheet href="chrome://test/content/bindings.css" type="text/css"?>
<mywindow id="myWindowID" width="800" height="600"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/x-javascript" src="chrome://greenfox/content/jquery-1.4.4.min.js" />
</mywindow>
and on mywindow constructor (at the binding) I use a function of my scrip, called 'print'.
The problem is that sometimes, my script doesn't load really fast before it's used, and I get the message
We are unable to Print or Print
Preview this page.
..which is related to the Printer usage.
Please note that I'm not trying to use the Printer, I'm trying to use my own print method (in the script that doesn't loaded in time) to simply write on the screen.
So, any idea how can I make the xul file wait till my script is completely loaded?
Solved it with a variable "window.scriptsLoaded" and a loop on my class constructor that wait..
-update
also, it didn't work with while(!window.scriptsLoaded), I needed to use:
function loadScripts() {
if (!window.scriptsLoaded)
setTimeout(loadScripts, 1)
else
loaded();
}
so the window.scriptsLoaded could be updated each time I check it. I don't really understand why.
-update
Actually, use "onload" showed itself a the better solution..