window.opener not working properly - javascript

I'm trying to use a simple scenario in which function from parent window is called from a popup.My source looks like this:
index.html
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Parent window</title>
</head>
<body>
<script type="text/javascript">
function twitterAccess() {
console.log('ok!')
}
window.open ("popup.html","mywindow", "width=350,height=250");
</script>
</body>
</html>
popup.html
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>popup</title>
</head>
<body>
<script type="text/javascript">
window.opener.twitterAccess()
</script>
</body>
</html>
But it allways gives me Uncaught TypeError: Object [object global] has no method 'twitterAccess'. I have also tried using it with window.parent, parent.window, parent.window.opener and a dozen of other suggestions found on the web but it's allways the same. Can you advice me on what am i doing wrong? I'm sure it's something really silly.

Related

AngularJS not show values

I read This article but still have question because I am new in AngularJS. I create Web Application and add AngularJS Core through Nuget Manager.
I try the code
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>First Page</title>
<script src="~/Scripts/angular.js"></script>
</head>
<body ng-app>
{{2+2}}
</body>
</html>
So, here I expect my web page shows 4 but it still shows expression.
Please help.
Check if your script is loading for angular.js.
DEMO
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>First Page</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
</head>
<body ng-app>
{{2+2}}
</body>
</html>

Get window top from <object> tag

Is it possible to fetch the window data of the "parent" window, from within a page loaded in a tag ?
I'm embedding a remote html file from https://test-static-app.herokuapp.com/ which simply outputs window.top and window.parent.top in the console.
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>Test</title>
<script type="text/javascript">
console.log('window.top', window.top.location);
console.log('window.parent.top', window.parent.top.location);
</script>
</head>
<body>
</body>
</html>
The result is for both values:
{}
Is it possible to get this data? How ?

Android TextView with HTML and JavaScript

I have this HTML:
<!DOCTYPE html> <html lang="en" xmlns:m="http://www.w3.org/1998/Math/MathML">
<head>
<meta charset="utf-8">
<script src="file:///android_asset/mathscribe/jquery-1.4.3.min.js"></script>
<script src="file:///android_asset/mathscribe/jqmath-etc-0.4.0.min.js"></script>
<title>Displaying maths</title> </head> <body> $$y-y_0=m(x-x_0)$$ </body> </html>
And I want to display the result in an Android TextView. I tried to use Html.fromHtml() but don't work.
it's: http://mathscribe.com/author/jqmath.html

Can't call javascript file from my html page

I'm new to JavaScript and just want to put my JavaScript code in another file.
This is my html page:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>my badass page</title>
<script type="text/javascript" scr = "testing.js"></script>//this contains the function I want to call
</head>
<body id="body">
<button type="button", onclick="showDate()">show the date</button>
</body>
</html>
This is the testing.js file:
function showDate() {
alert ("this works")
}
I'm assuming that I just make a beginner mistake because it seems really common but I can't figure it out.
you spelled the 'src' attribute incorrectly on your tag
you spelled it scr, it should be src
this:
<script type="text/javascript" scr = "testing.js"></script>
should be this:
<script type="text/javascript" src = "testing.js"></script>
change the button to
<button type="button" onclick="showDate()">show the date</button>
and change scr to src
EDIT: source that works:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>my badass page</title>
<script type="text/javascript" src="testing.js">
</script>
</head>
<body id="body">
<button type="button" onclick="showDate();">show the date</button>
</body>
</html>
Quick use of html validator such as http://validator.w3.org/nu/ will uncover lots of problems in your code. Just copy paste and correct the errors.

JavaScript won't work if placed inside the body of a web page?

I'm new to JavaScript and I've learned that JavaScript can be place between the <head></head> or <body></body> sections, I have been working in a project and it works fine inside the head but not the body section of the page.
examples:
working fine like this:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Example Page</title>
<script>
function yetAnotherAlert(textToAlert) {
alert(textToAlert);
}
yetAnotherAlert("Hello World");
And is not working this way:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Example Page</title>
</head>
<body>
<script>
function yetAnotherAlert(textToAlert) {
alert(textToAlert);
}
yetAnotherAlert("Hello World");
</script>
</body>
</html>
Your code snippet didn't show you closing the tag. Double check if you close your script block correctly.
It's also better to specify the type of scripting language too.
<script language='javascript'>
....
</script>

Categories

Resources