How to get current iframe url in a javascript var [duplicate] - javascript

This question already has answers here:
Getting the current src of an Iframe using JQuery [duplicate]
(4 answers)
Closed 8 years ago.
Hello guys i kind of a javascript newbie.
Here is my problem
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
</head>
<body>
<iframe name='frmExternal' id='frmExternal' src='www.dynamically-changing-url.com'></frame>
</body>
</html>
I want to get the current url in the iframe where the user browse along.

document.getElementsByName('frmExternal')[0].src

Related

Accessing variables from different files [duplicate]

This question already has answers here:
Share data between HTML pages
(4 answers)
Closed 2 years ago.
I have a project I'm working on that has multiple pages. Both of them have a JavaScript tag.
I want to be able to get a variable from the other one.
First HTML
<html>
<head></head>
<body>
<script>
var example = "stringText"
</script>
</body>
</html>
Second HTML
<html>
<head></head>
<body>
<script>
console.log(example)
</script>
</body>
</html>
I have tried making a .js file and saving a variable there and accessing it from the other file but it didn't work, the variable would clear itself when it got to the other page.
It is a possible way to approach.

My JavaScript redirection code is not working [duplicate]

This question already has answers here:
execute a function after redirecting - javascript
(3 answers)
Closed 4 years ago.
<!DOCTYPE html>
<html>
<head>
<title>Experiment</title>
</head>
<body>
<script>
location.href = "https://www.bing.com";
function rere()
{
location.href = "https://www.google.com";
}
window.onload=function(){setTimeout(rere, 5000);};
</script>
</body>
</html>
I want to do following operations:
Go to a Location.
Wait until page loading.
Then go to a new location.
But, it stacked only at the first location.
Because the JavaScript is part of your currently open page. When a new page is loaded, it is stopped. So your Javascript is no longer running, now it's Bing's turn.
You might want to check iframes.

how to open a document when loading a web page [duplicate]

This question already has answers here:
Javascript Excel OpenFile
(2 answers)
Closed 5 years ago.
I want to open a excel document while loading a web page but i don't know how. I tried this:
<script>
function myFunction() {
window.open("file:///D://Files/doc.xlsx");
}
</script>
<body onload="myFunction()">
</body>
But it didn't work. I want to mention that it has to be done for IE8 and less.
Add tag <script> to <head>
<head>
<script>
function myFunction() {
window.open("file:///D://Files/doc.xlsx");
}
</script>
</head>
<body onload="myFunction()">
</body>

button not working in JSFiddle [duplicate]

This question already has answers here:
Why isn't my JavaScript working in JSFiddle?
(7 answers)
Closed 6 years ago.
This works:
<html>
<script type="text/javascript">
function lala() {
console.log("lala");
}
</script>
<body>
<button onclick="lala()">lala</button>
</body>
</html>
But having that in jsfiddle works not:
<button onclick="lala()">lala</button>
function lala() {
console.log("lala");
}
https://jsfiddle.net/clankill3r/715kha38/
Uncaught ReferenceError: lala is not defined
I saw some old answers on stackoverflow regarding this problem but those seem to be invalid those days.
Please change Load type in java script section select
No wrap - in <head>

Why does this Javascript document.write not execute? [duplicate]

This question already has answers here:
JavaScript: Inline Script with SRC Attribute?
(3 answers)
Closed 8 years ago.
When I launch this in chrome, nothing appears on the page.
<!DOCTYPE html>
<head><title>test 4000</title><head>
<body>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js">
document.writeln("test")
</script>
</body>
</html>
you are inserting code in a script tag that you are also using to load an external script (jQuery). you should either do the one or the other.
<script>
document.writeln("test");
</script>
if you want both do:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
document.writeln("test");
</script>
the reference states:
If the src has a URI value, user agents must ignore the element's contents and retrieve the script via the URI.
you do not need to include jQuery to use document.writeln()

Categories

Resources