I've this script:
<html>
<head>
<script type="text/javascript">
function init(){
var extText = window.frames.messageTxt.document.body.lastChild.lastChild.data;
extText = extText.replace(/[\r\n]/g," ");
document.forms[0].nMessage.value = extText;
}
window.onload=init;
</script>
</head>
<body>
<iframe name='messageTxt' src='lineData.txt' style='display:none'></iframe>
<form>
<textarea name='nMessage'></textarea>
</form>
</body>
</html>
This code open a file (now lineData.txt) and put it on a textarea. This code works on Firefox and IE but doesn't work on Chrome.
The problem is on
window.frames.messageTxt.document.body.lastChild.lastChild.data;
The console tell me in that line:
Uncaught TypeError: Cannot read property 'body' of undefined
How can I do to make it works on Chrome ?
If you are testing locally (eg file://C:/.../test.html) you won't be able to properly access frames/iframes in Chrome.
Related
I am using:
if($(this).length > 0){
alert(this.files[0].name);
}
The JS is in this HTML:
<input type="file" onchange="{JS_FROM_ABOVE}">
Works fine in Chrome but in IE I get:
Unable to get property 'name' of undefined or null reference
Any advice or workaround?
I try to test your sample code with the IE 11 browser and found that it is working fine.
Tested code:
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
});
</script>
</head>
<body>
<input type="file" onchange="if($(this).length > 0){
alert(this.files[0].name);}">
</body>
</html>
Output in IE 11 browser:
I suggest trying to run my above test code on your side to check for the result. See if it works for you.
If the issue persists then please inform us which version of the IE browser you are using for making this test? Let us know which version of the JQuery you are using for making this test. It may help to narrow down the issue.
If use following way to get the contentWindow, the value is undefined
<html>
<head>
<title>iframe test</title>
</head>
<body>
<iframe id="frame1" src="frame1.html" name="frame1"></iframe>
<script>
document.body.onload = function() {
console.info("index loaded");
var frame1 = window.frames["frame1"];
console.info(frame1.contentWindow);
}
</script>
</body>
</html>
If use the other way like following, it works fine:
var frame1 = document.getElementById("frame1");
console.info(frame1.contentWindow);
I tested on FF 29.0.1, chrome 34, IE11, they all work the same way.
So I have two questions:
why the first way can't get contentWindow value
iframe.contentWindow is compatible in all browser?
window.frames["frame1"];
is the contentWindow, it gets a named window, and in your case it's the same thing as
document.getElementById("frame1").contentWindow
FIDDLE
I have code that works in Chrome and IE to pop-up a chat window but not working in FireFox.
- FireFox error "TypeError: window._laq is undefined"
The JS code:
<script type="text/javascript">
if (!window._laq) { window._laq = []; }
window._laq.push(function(){chat.showWhenOnline('123123', document.getElementById('chat_button_online_123123'));
chat.showWhenOffline('123123', document.getElementById('chat_button_offline_123123'));
});
</script>
It's is called by clicking an image button.. The code:
<a class="chaticon" id="chat_button_online_123123"
onclick="chat.startChat('123123')">
<img src="http://myDomain.com/chatIcon_on.jpg" border="0" alt="Need Help? Live Chat!" />
</a>
Any ideas?
Thanks
/Shane
you have to insert
<script type='text/javascript' src='https://c.la1-c1cs-lon.salesforceliveagent.com/content/g/js/34.0/deployment.js'></script>
before your script.
In that way the system should recognize the command window._laq.
Haven't been programming in JS for a while.
Now, I have following thing:
<html>
<head>
<script language="JavaScript">
function enlarge()
{
window.close();
}
</script>
</head>
<body>
<img src="addresstomyimg.png" onClick="enlarge()" />
</body>
</html>
(it's very simplified, as, in fact, I have WordPress platform with custom JS modifications etc, but in general, this is the idea).
I don't understand why it's not working.
JavaScript cant close the window unless it opened the window.
In your function, replace window.close() with alert('here') and you'll see the function works fine.
If you want your function to close a window, first open one:
<html>
<head>
<script type="text/javascript">
var popup;
function closewin()
{
popup.close();
}
function openwin()
{
popup = window.open('http://www.google.com');
}
</script>
</head>
<body>
<img src="addresstomyimg.png" onclick="openwin()" /> Click to open, then come back here
<br><br>
<img src="addresstomyimg.png" onclick="closewin()" /> Click to close
</body>
</html>
Demo: http://jsfiddle.net/AlienWebguy/pbFha/
If you try running this script using Firefox and use the Firefox's Error Console to look for errors, you can see that the following error gets logged when you run this script.
Scripts may not close windows that were not opened by script.
You can launch the Error Console in Firefox by pressing Ctrl + Shift + J.
On Chrome, your script successfully closes the tab in which it is running.
Note that the right way to use the <script> tag while writing JavaScript is as follows:
<script type="text/javascript">
If you're trying to close the main window, it won't work.
You can only close windows that were opened by JavaScript.
This code works on IE.
<html>
<head>
<script language="JavaScript">
function enlarge()
{
self.close();
}
</script>
</head>
<body>
<img src="addresstomyimg.png" onClick="enlarge()" />
</body>
</html>
If I run the below code as regular html5 code in the browser, Its works fine. I want the same result using android. I am getting the following error:
12-08 12:56:26.546: ERROR/Web Console(703): TypeError: Result of
expression 'service.useService' [undefined] is not a function. at
file:///android_asset/www/index.html:12
<!DOCTYPE HTML>
<html>
<head>
<title>Hello World</title>
<script language="JavaScript">
var iCallID;
function InitializeService()
{
service.useService("http://10.15.1.205/HelloService/Service.asmx?wsdl", "HelloWorldService");
service.HelloWorldService.callService("HelloWorld");
}
function ShowResult()
{
document.write(event.result.value);
}
</script>
</head>
<body onload="InitializeService()" id="service" style="behavior:url(webservice.htc)" onresult="ShowResult()">
</body>
</html>
This isnt a problem with HTML5 this is a Internet Explorer only CSS attribute -> http://msdn.microsoft.com/en-us/library/ms530723(v=vs.85).aspx
Cannot find it in any official HTML5 / CSS3 documentation ...
So unless your Android device runs Internet Explorer you need to find an alternative