I have one popup window, when user opens and closes popup window simultaneously, it is giving script error. Below code is used in popup window.
<html>
<head>
<script src="../../StaticContent/Scripts/jquery-1.7.2.min.js"
type="text/javascript"></script>
<script src="../../StaticContent/Scripts/jquery-ui-1.8.20.custom.js"
type="text/javascript"></script>
<script type="text/javascript" language="javascript">
function CloseWarning() {
return "Do you want to close the window";
}
function onload()
{
}
</script></head>
<body onbeforeunload="return CloseWarning();" onload="onload();">
//Some html
<script type="text/javascript" language="javascript">
$(document).ready(
function() {
//Some code
});
</script>
</body>
</html>
I have tried degubbing, it is giving error at $(document).ready() line. I think because of closing the popup window before fully loading HTML is causing this problem.
Any clues???
you have ()() as double in the function declaration. change like below.
function CloseWarning(){
return "Do you want to close the window";
}
Related
I am using Google Chrome Version 81.0.4044.138.
When I try to open/refresh the html file I have with the following code, the page content does not appear until I click the OK button on the alert dialog. How can I fix this so that the content and the dialog are shown?
I have tried this on MS Edge as well with the same issue...
Any assistance greatly appreciated!
<!doctype html>
<html>
<head>
<title>Javascript</title>
</head>
<body>
<p>Hello World!</p>
<script type="text/javascript">
alert("Hello, World!");
</script>
</body>
</html>
Alert freezes the page by design. You could try modifying your code a bit:
<script type="text/javascript">
window.addEventListener('load', () => {
alert("Hello, World!");
});
</script>
SO, I know how to create a popup window in google, and I know how to write in the popup window, but how do I put in other HTML tags in a popup window?
The Html code that I have is below.
<html>
<head>
<script>
function openWin()
{
myWindow=window.open("","","width=200,height=100");
myWindow.document.write("<p>NEW WINDOW<p>");
}
</script>
</head>
<body>
<button onmousedown='openWin();'>Hello</button>
</body>
</html>
As you can see, in the document.write function, I have two <p> tags, and I can also use the <button> tag, but I cannot use the <script> tag, does anyone know why, or if it is possible?
So you're trying to write a <script> tag to your popup window? You have to do it like this:
<html>
<head>
<script>
function openWin()
{
myWindow=window.open("","","width=200,height=100");
myWindow.document.open();
myWindow.document.write("<p>NEW WINDOW<p>");
myWindow.document.write("<scr" + "ipt>alert('Script works!')</scr"+"ipt>");
myWindow.document.close();
}
</script>
</head>
<body>
<button onmousedown='openWin();'>Hello</button>
</body>
</html>
Otherwise the parent window will think the script tags are something it should interpret.
You cannot write "<script>" or "</script>" to the window, these are specifically disallowed. You have to split up these terms.
function openWin() {
myWindow=window.open("","","width=200,height=100");
myWindow.document.write("<p>NEW WINDOW<p>");
myWindow.document.write("<scr");
myWindow.document.write("ipt>alert('Script works!')</scr")
myWindow.document.write("ipt>");
}
I need to disable right click on a Anchor tag/hyperlink in page/popup open in iframe using javascript/jquery?
I have below code logic which works when I open page in iframe but not work when I open popup in Iframe by clicking on link within the Iframe page.
In below example when I right-click on Open Popup link its not allowing the right click but when I open popup by clicking Open Popup link it's not working for links in popup.
Any suggestions?
Below sample code snippet for reference -
TestPage.html
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<title>Test Page</title>
</head>
<body>
<iframe id="sampleIframe" src="PopupPage.html" width="400" height="150"></iframe>
<script language="javascript" type="text/javascript">
$('#sampleIframe').load(function() {
$('#sampleIframe').contents().find('a').each(function() {
$(this).on("contextmenu", function() {
return false;
});
});
});
</script>
</body>
</html>
PopupPage.html
<html>
<head>
<title>Popup Page</title>
</head>
<body>
You are on popup page.
Open Popup
<script language="javascript" type="text/javascript">
function openPopup() {
window.open("LinkPage.html", null,
"height=200,width=400,status=yes,toolbar=no,menubar=no,location=no");
}
</script>
</body>
</html>
LinkPage.html
<html>
<head>
<title>Link Page</title>
</head>
<body>
Goto Google
Goto Facebook
</body>
</html>
For this to work, you need to include your script to disable the links in the actual iFrame content.
To demonstrate, create a jsfiddle with this code (it will not let me save it to post a link)
This would be your "LinkPage.html"
HTML
Open Popup
JAVASCRIPT
function openPopup() {
window.open("http://jsfiddle.net/t45qvtap/1/show", null,
"height=200,width=400,status=yes,toolbar=no,menubar=no,location=no");
}
And you will see it working.
Just to explain further, this is the contents of the fiddle that the above code will open in an iFrame, this would be your "PopupPage.html"
HTML
This content is in an iframe
<div>
Goto Google
Goto Facebook
</div>
JAVASCRIPT
$('body').contents().find('a').each(function() {
$(this).on("contextmenu", function() {
return false;
});
});
I want a popup window containing a canvas, but I'm unable to get the JS to work in the popup.
Here's a toy program that shows the problem, trying to get 'alert' to work in the popup.
<html> <head> <title> popup test </title>
<script language="javascript">
function popup()
{OpenWindow=window.open("","","height=250,width=250");
OpenWindow.document.write("<html><body bgcolor=pink>Hello!");
OpenWindow.document.write("<form><input type='button' value='alert' onclick='doalert()'></form> ");
OpenWindow.document.write("</body></html>");
}
function doalert() { alert("Got in");}
</script> </head>
<body>
<input type="button" onclick='popup()' value="click to see new window">
</body></html>
The alert button shows in the popup window, blinks when I click it, but doesn't put up the alert box.
Define doalert in the child window:
<html> <head> <title> popup test </title>
<script language="javascript">
function popup() {
OpenWindow=window.open("","","height=250,width=250");
OpenWindow.document.write("<html><body bgcolor=pink>Hello!");
OpenWindow.document.write('<script language="javascript">function doalert() { alert("Got in"); } <\/script>');
OpenWindow.document.write("<form><input type='button' value='alert' onclick='doalert()'></form>");
OpenWindow.document.write("</body></html>");
}
</script> </head>
<body>
<input type="button" onclick='popup()' value="click to see new window">
</body></html>
The "doalert()" must be initiated only when the new window get loaded. Put these kind of functions which are needed to be work in parent window and child window in a function and trigger them when each window opens are when new codes are inserted or included to a page.
I'm juuuuuust trying to get an pop up displaying test when the document is ready. I've managed to get google maps working on another page but somehow this is a lot of pain.
Here's the code:
<html>
<head>
[...]
<script type="text/javascript" href="https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"></script>
{literal}
<script type="text/javascript">
$(document).ready(function () {
alert ("test");
});
</script>
{/literal}
</head>
[...]
</html>
What should I do to get that popup message? I also tried copy pasting from my working jquery page without much success.
Changing <script href=...> to <script src=...> works like a charm for me.
Does you javascript is enabled in your browser ?
You can type this:
$(function() {
alert("test");
});